public Update ( |
||
entity | ||
Результат | int |
public int Update(lkup_faclty entity)
{
try
{
using ( var ctx = new ClinicDataContext(connString) )
{
var currentFacility = ctx.lkup_faclty.FirstOrDefault(x => x.faclty_id == entity.faclty_id);
if ( currentFacility == null )
{
throw new Exception("Record doesn't exist and cannot be updated");
}
currentFacility.faclty_id = entity.faclty_id;
currentFacility.faclty_stat = entity.faclty_stat;
currentFacility.hlth_care_faclty = entity.hlth_care_faclty;
currentFacility.cntry = entity.cntry;
currentFacility.faclty_strt_eff_dt = entity.faclty_strt_eff_dt;
currentFacility.faclty_end_eff_dt = entity.faclty_end_eff_dt;
currentFacility.hlth_care_faclty_lvl = entity.hlth_care_faclty_lvl;
currentFacility.hlth_coordtr = entity.hlth_coordtr;
currentFacility.lattd = entity.lattd;
currentFacility.longtd = entity.longtd;
currentFacility.orgzn_id = entity.orgzn_id;
currentFacility.rec_updt_dt = entity.rec_updt_dt;
currentFacility.rec_updt_user_id_cd = entity.rec_updt_user_id_cd;
currentFacility.rgn = entity.rgn;
currentFacility.setlmt = entity.setlmt;
currentFacility.user_intrfc_sort_ord = entity.user_intrfc_sort_ord;
ctx.Entry(currentFacility).State = System.Data.Entity.EntityState.Modified;
int result = ctx.SaveChanges();
return result;
}
}
catch ( DbEntityValidationException ex )
{
throw ex;
}
catch ( EntityException ex )
{
throw ex;
}
catch ( Exception ex )
{
throw ex;
}
}
public int UpdateFacility(FacilityModel model) { var repo = new FacilityRepository(); var dataModel = new HealthInformationProgram.Data.Tables.lkup_faclty(); try { dataModel.faclty_id = Convert.ToDecimal(model.FacilityId); dataModel.hlth_care_faclty = model.HealthCareFacility; dataModel.hlth_care_faclty_lvl = model.HealthCareFacilityLevel; dataModel.hlth_coordtr = model.HealthCoordinator; dataModel.setlmt = model.Settlement; dataModel.cntry = model.Country; dataModel.rgn = model.Region; dataModel.orgzn_id = Convert.ToDecimal(model.OrganizationId); dataModel.faclty_stat = model.FacilityStatus; dataModel.faclty_strt_eff_dt = Convert.ToDateTime(model.FacilityStartEffectiveDate); dataModel.faclty_end_eff_dt = Convert.ToDateTime(model.FacilityEndEffectiveDate); dataModel.user_intrfc_sort_ord = Convert.ToDecimal(model.SortOrder); dataModel.lattd = Convert.ToDecimal(model.Latitude); dataModel.longtd = Convert.ToDecimal(model.Longitude); dataModel.rec_creat_dt = DateTime.Now; dataModel.rec_creat_user_id_cd = model.CreatedBy; dataModel.rec_updt_dt = DateTime.Now; dataModel.rec_updt_user_id_cd = model.UpdatedBy; var returnCode = repo.Update(dataModel); return returnCode; } catch ( Exception ex ) { throw ex; } }