public void UpdatePresentenceSummaries(PCMPresentenceDetailsViewModel cases, int userId, int Summary_Id) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_Summaries editCase = db.PCM_Presentence_Summaries.Find(Summary_Id); if (Summary_Id > 0) { /****** Script for SelectTopNRows command from SSMS ******/ editCase.Education_Sammary = cases.Education_Sammary; editCase.IsAssessed = cases.IsAssessed; editCase.Offence_Sammary = cases.Offence_Sammary; editCase.Victim_Sammary = cases.Victim_Sammary; editCase.Date_Modified = DateTime.Now; editCase.Modified_By = userId; } 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 = new InvalidOperationException(message, raise); } } throw raise; } } }
public void InsertPresentenceSummaries(PCMPresentenceDetailsViewModel cases, int intassid, int userId) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_Summaries newCase = new PCM_Presentence_Summaries(); newCase.Intake_Assessment_Id = intassid; newCase.Education_Sammary = cases.Education_Sammary; newCase.Offence_Sammary = cases.Offence_Sammary; newCase.Victim_Sammary = cases.Victim_Sammary; newCase.Created_By = userId; newCase.Date_Created = DateTime.Now; db.PCM_Presentence_Summaries.Add(newCase); 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 PCMPresentenceDetailsViewModel GetPresentenseSummaryList(int Summary_Id) { PCMPresentenceDetailsViewModel fvm = new PCMPresentenceDetailsViewModel(); using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_Presentence_Summaries act = db.PCM_Presentence_Summaries.Find(Summary_Id); fvm.Presentence_Summary_Id = act.Presentence_Summary_Id; fvm.Education_Sammary = act.Education_Sammary; fvm.Offence_Sammary = act.Offence_Sammary; fvm.Victim_Sammary = act.Victim_Sammary; fvm.IsAssessed = act.IsAssessed; } 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(fvm); } }