public void UpdateProceeding(PCMFCRViewModel vm, int FormalCourt_Id, int Intake_Assessment_Id, int userId) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_FCR_Proceeding pp = db.PCM_FCR_Proceeding.Find(FormalCourt_Id); pp.Intake_Assessment_Id = Intake_Assessment_Id; pp.Formal_Court_Id = vm.Court_Id; pp.Appearance_Date = vm.Appearance_Date; db.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public void AddProceeding(PCMFCRViewModel pVM, int Intake_Assessment_Id, int userId) { using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities()) { try { PCM_FCR_Proceeding newProceeding = new PCM_FCR_Proceeding(); newProceeding.Intake_Assessment_Id = Intake_Assessment_Id; newProceeding.Formal_Court_Id = pVM.Court_Id; newProceeding.Appearance_Date = pVM.Appearance_Date; db.PCM_FCR_Proceeding.Add(newProceeding); db.SaveChanges(); PCM_FCR_Outcome newOutcome = new PCM_FCR_Outcome(); newOutcome.Intake_Assessment_Id = Intake_Assessment_Id; newOutcome.FormalCourt_Id = newProceeding.FormalCourt_Id; db.PCM_FCR_Outcome.Add(newOutcome); 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; } } }