public ActionResult Index(SummonViewModel model) { try { model.Summon.DateReported = DateTime.Now.Date; model.Summon.SummonId = KeyGenerator.GenerateId(model.Summon.ReportDescription); entities.Summons.Add(model.Summon); entities.SaveChanges(); foreach (var resident in model.CheckBoxes) { if (resident.IsSelected == true) { entities.SummonInvolvedResidents.Add(new SummonInvolvedResident() { ResidentId = resident.ResidentId, SummonId = model.Summon.SummonId, InvolvedId = KeyGenerator.GenerateId(resident.FullName) }); entities.SaveChanges(); } } TempData["alert-type"] = "alert-success"; TempData["alert-header"] = "Success"; TempData["alert-msg"] = "A Summon report was succesfully created with an ID of " + model.Summon.SummonId + ". Please copy this id as reference."; // Audit Trail string userId = User.Identity.GetUserId(); new AuditTrailer().Record("Created a summon report with an id " + model.Summon.SummonId, AuditTrailer.SUMMON_TYPE, userId); return(RedirectToAction("Index")); } catch (Exception e) { TempData["alert-type"] = "alert-danger"; TempData["alert-header"] = "Error"; TempData["alert-msg"] = "Something went wrong, please try again later." + e.ToString(); return(RedirectToAction("Index")); } }
public ActionResult Index() { try { TempData["user-profile-photo"] = UserHelper.GetDisplayPicture(User.Identity.GetUserId(), entities); SummonViewModel viewModel = new SummonViewModel(); List <ResidentsInformation> residents = entities.ResidentsInformations.Where(m => m.Deceaseds.FirstOrDefault() == null).ToList(); viewModel.CheckBoxes = new SummonViewModel.CheckBoxModel[residents.Count()]; int ctr = 0; foreach (var resident in residents) { var temp = new SummonViewModel.CheckBoxModel() { IsSelected = false, ResidentId = resident.ResidentId, FullName = resident.FirstName + " " + resident.LastName }; viewModel.CheckBoxes[ctr++] = temp; } viewModel.CheckBoxes = viewModel.CheckBoxes.OrderBy(m => m.FullName).ToArray(); TempData["Status"] = entities.SummonStatus.ToList(); return(View(viewModel)); } catch (Exception e) { TempData["alert-type"] = "alert-danger"; TempData["alert-header"] = "Error"; TempData["alert-msg"] = "Something went wrong, please try again later." + e.ToString(); return(View()); } }