public void UpdateSentenseDetails(PCMPresentenceDetailsViewModel vm, int Sentence_Id, int userId) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_OutCome newCase = db.PCM_Presentence_OutCome.Find(Sentence_Id); newCase.Sentence_Id = Sentence_Id; newCase.Court_Date = vm.Court_Date; newCase.Reason_for_Remand = vm.Reason_for_Remand; newCase.NextCourtDate = vm.NextCourtDate; newCase.Court_Outcome = vm.Court_Outcome; newCase.Community_Based_Options_Id = vm.Community_Based_Options_Id; newCase.Restorective_Justice_Option_Id = vm.Restorective_Justice_Option_Id; newCase.Programme_Type_Id = vm.Programme_Type_Id; newCase.Programme_Id = vm.Programme_Id; newCase.Fine_or_Alternatives_To_Fine = vm.Fine_or_Alternatives_To_Fine; newCase.Fine_Alternatives_Fine_Comments = vm.Fine_Alternatives_Fine_Comments; newCase.Suspended_Postponed_Sentence_Id = vm.Suspended_Postponed_Sentence_Id; newCase.Commital_Treatment_Centre = vm.Commital_Treatment_Centre; newCase.Center_Name = vm.Center_Name; newCase.Center_Name_CYCC = vm.CYCCCenter_Name; newCase.Period_Commital_Treatment_Centre_From = vm.Period_Commital_Treatment_Centre_From; newCase.Period_Commital_Treatment_Centre_To = vm.Period_Commital_Treatment_Centre_To; newCase.Compulsory_esidence_CYCC = vm.Compulsory_esidence_CYCC; newCase.Compulsory_esidence_CYCC_From = vm.Compulsory_esidence_CYCC_From; newCase.Compulsory_esidence_CYCC_To = vm.Compulsory_esidence_CYCC_To; newCase.Imprisoment = vm.Imprisoment; newCase.Imprisoment_Id = vm.Imprisoment_Id; newCase.Imprisomen_From = vm.Imprisomen_From; newCase.Imprisomen_To = vm.Imprisomen_To; newCase.Department_Id = vm.Department_Id; newCase.PCM_Case_Status_Id = vm.PCM_Case_Status_Id; newCase.Modified_By = userId; newCase.Date_Modified = DateTime.Now; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } } }
public void CreateSentenseDeatils(PCMPresentenceDetailsViewModel vm, int caseid, int userId) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_OutCome newCase = new PCM_Presentence_OutCome(); newCase.Court_Date = vm.Court_Date; newCase.Reason_for_Remand = vm.Reason_for_Remand; newCase.NextCourtDate = vm.NextCourtDate; newCase.Court_Outcome = vm.Court_Outcome; newCase.Community_Based_Options_Id = vm.Community_Based_Options_Id; newCase.Restorective_Justice_Option_Id = vm.Restorective_Justice_Option_Id; newCase.Programme_Type_Id = vm.Programme_Type_Id; newCase.Programme_Id = vm.Programme_Id; newCase.Fine_or_Alternatives_To_Fine = vm.Fine_or_Alternatives_To_Fine; newCase.Fine_Alternatives_Fine_Comments = vm.Fine_Alternatives_Fine_Comments; newCase.Suspended_Postponed_Sentence_Id = vm.Suspended_Postponed_Sentence_Id; newCase.Commital_Treatment_Centre = vm.Commital_Treatment_Centre; newCase.Center_Name = vm.Center_Name; newCase.Center_Name_CYCC = vm.CYCCCenter_Name; newCase.Period_Commital_Treatment_Centre_From = vm.Period_Commital_Treatment_Centre_From; newCase.Period_Commital_Treatment_Centre_To = vm.Period_Commital_Treatment_Centre_To; newCase.Compulsory_esidence_CYCC = vm.Compulsory_esidence_CYCC; newCase.Compulsory_esidence_CYCC_From = vm.Compulsory_esidence_CYCC_From; newCase.Compulsory_esidence_CYCC_To = vm.Compulsory_esidence_CYCC_To; newCase.Imprisoment = vm.Imprisoment; newCase.Imprisoment_Id = vm.Imprisoment_Id; newCase.Imprisomen_From = vm.Imprisomen_From; newCase.Imprisomen_To = vm.Imprisomen_To; newCase.Department_Id = vm.Department_Id; newCase.PCM_Case_Status_Id = vm.PCM_Case_Status_Id; newCase.Created_By = userId; newCase.Date_Created = DateTime.Now; newCase.Intake_Assessment_Id = caseid; db.PCM_Presentence_OutCome.Add(newCase); db.SaveChanges(); } catch { } } }
public PCMPresentenceDetailsViewModel GetPCMSentenseOnEditDetails(int Sentence_Id) { PCMPresentenceDetailsViewModel vm = new PCMPresentenceDetailsViewModel(); using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_OutCome act = db.PCM_Presentence_OutCome.Find(Sentence_Id); if (act != null) { vm.Sentence_Id = act.Sentence_Id; vm.Court_Date = act.Court_Date; vm.Reason_for_Remand = act.Reason_for_Remand; vm.NextCourtDate = act.NextCourtDate; vm.Court_Outcome = act.Court_Outcome; vm.Community_Based_Options_Id = act.Community_Based_Options_Id; if (act.Community_Based_Options_Id != null) { vm.SelectCommunityBasedOptionsDetails = db.apl_PCM_Community_Based_Options.Find(act.Community_Based_Options_Id).Description; } vm.Restorective_Justice_Option_Id = act.Restorective_Justice_Option_Id; if (act.Restorective_Justice_Option_Id != null) { vm.SelectRestorectiveJusticeDetails = db.apl_Restorective_Justice_Types.Find(act.Restorective_Justice_Option_Id).Description; } vm.Programme_Type_Id = act.Programme_Type_Id; if (act.Programme_Type_Id != null) { vm.SelectProgrammeTypeDetails = db.apl_Programme_Type.Find(act.Programme_Type_Id).Description; } vm.Programme_Id = act.Programme_Id; if (act.Programme_Id != null) { vm.SelectProgrammeDetails = db.apl_Programmes.Find(act.Programme_Id).Programme_Name; } vm.Fine_or_Alternatives_To_Fine = act.Fine_or_Alternatives_To_Fine ?? false; vm.Fine_Alternatives_Fine_Comments = act.Fine_Alternatives_Fine_Comments; vm.Suspended_Postponed_Sentence_Id = act.Suspended_Postponed_Sentence_Id; if (act.Suspended_Postponed_Sentence_Id != null) { vm.SelectSupendedPostponedSentenceDetails = db.apl_PCM_Supended_Postponed_Sentence.Find(act.Suspended_Postponed_Sentence_Id).Description; } vm.Commital_Treatment_Centre = act.Commital_Treatment_Centre ?? false;; vm.Center_Name = act.Center_Name; vm.CYCCCenter_Name = act.Center_Name_CYCC; vm.Period_Commital_Treatment_Centre_From = act.Period_Commital_Treatment_Centre_From; vm.Period_Commital_Treatment_Centre_To = act.Period_Commital_Treatment_Centre_To; vm.Compulsory_esidence_CYCC = act.Compulsory_esidence_CYCC ?? false; vm.Compulsory_esidence_CYCC_From = act.Compulsory_esidence_CYCC_From; vm.Compulsory_esidence_CYCC_To = act.Compulsory_esidence_CYCC_To; vm.Imprisoment = act.Imprisoment ?? false; vm.Imprisoment_Id = act.Imprisoment_Id; if (act.Imprisoment_Id != null) { vm.SelectImprisomentDetails = db.apl_PCM_Imprisoment.Find(act.Imprisoment_Id).Description; } vm.Imprisomen_From = act.Imprisomen_From; vm.Imprisomen_To = act.Imprisomen_To; vm.Department_Id = act.Department_Id; if (act.Department_Id != null) { vm.SelectDepartmentDetails = db.apl_Department.Find(act.Department_Id).Description; } vm.PCM_Case_Status_Id = act.PCM_Case_Status_Id; if (act.PCM_Case_Status_Id != null) { vm.SelectCaseStatusDetails = db.apl_PCM_Case_Status.Find(act.PCM_Case_Status_Id).Description; } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(vm); } }