HealthInformationProgram.Data.Repositories.SupplementalDiagnosisCategoryRepository.Update C# (CSharp) Method

Update() public method

public Update ( lkup_splmtl_diag_cat entity ) : int
entity HealthInformationProgram.Data.Tables.lkup_splmtl_diag_cat
return int
        public int Update(lkup_splmtl_diag_cat entity)
        {
            try
            {
                using ( var ctx = new ClinicDataContext(connString) )
                {
                    var supplementalDiagnosisCategories = ctx.lkup_splmtl_diag_cat.FirstOrDefault(x => x.splmtl_diag_cat_id == entity.splmtl_diag_cat_id);
                    if ( supplementalDiagnosisCategories == null )
                    {
                        throw new Exception("Record doesn't exist and cannot be updated");
                    }
                    supplementalDiagnosisCategories.splmtl_diag_cat_id = entity.splmtl_diag_cat_id;
                    supplementalDiagnosisCategories.splmtl_diag_cat = entity.splmtl_diag_cat;
                    supplementalDiagnosisCategories.user_intrfc_sort_ord = entity.user_intrfc_sort_ord;
                    supplementalDiagnosisCategories.splmtl_diag_cat_stat = entity.splmtl_diag_cat_stat;
                    supplementalDiagnosisCategories.splmtl_diag_cat_strt_eff_dt = entity.splmtl_diag_cat_strt_eff_dt;
                    supplementalDiagnosisCategories.splmtl_diag_cat_end_eff_dt = entity.splmtl_diag_cat_end_eff_dt;

                    supplementalDiagnosisCategories.rec_updt_user_id_cd = entity.rec_updt_user_id_cd;
                    supplementalDiagnosisCategories.rec_updt_dt = entity.rec_updt_dt;

                    ctx.Entry(supplementalDiagnosisCategories).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;
            }
        }

Usage Example

Esempio n. 1
0
        public int UpdateSupplementalDiagnosisCategory(SupplementalDiagnosisCategoryModel model)
        {
            var repo = new SupplementalDiagnosisCategoryRepository();
            var dataModel = new HealthInformationProgram.Data.Tables.lkup_splmtl_diag_cat();

            dataModel.splmtl_diag_cat_id = Convert.ToDecimal(model.SupplementalDiagnosisCategoryId);
            dataModel.splmtl_diag_cat_stat = model.Status;
            dataModel.splmtl_diag_cat = model.SupplementalDiagnosisCategoryType;
            dataModel.user_intrfc_sort_ord = Convert.ToDecimal(model.SortOrder);
            dataModel.splmtl_diag_cat_strt_eff_dt = Convert.ToDateTime(model.SupplementalDiagnosisCategoryEffectiveStartDate);
            dataModel.splmtl_diag_cat_end_eff_dt = Convert.ToDateTime(model.SupplementalDiagnosisCategoryEffectiveEndDate);

            dataModel.rec_updt_dt = DateTime.Now;
            dataModel.rec_updt_user_id_cd = model.UpdatedBy;

            try
            {

                var returnCode = repo.Update(dataModel);
                return returnCode;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }