public ActionResult EditDisplay([Bind(Include = "ID, Bedroom, Bathroom, SqrFeet, Year")] Home home) { if (ModelState.IsValid) { db.Entry(home).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Display")); } return(View(home)); }
public ActionResult Edit([Bind(Include = "Id,First_Name,Last_Name,MiddleName,DOB,JoiningDate,LeavingDate,Resident_Address")] Resident resident) { if (ModelState.IsValid) { db.Entry(resident).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(resident)); }
public ActionResult Edit([Bind(Include = "MilitaryCampaignID,CampaignName")] MilitaryCampaign militaryCampaign) { if (ModelState.IsValid) { db.Entry(militaryCampaign).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(militaryCampaign)); }
public ActionResult Edit([Bind(Include = "Id,First_Name,Last_Name,Gender,Phone,Address,MedicalCondition")] Resident resident) { if (ModelState.IsValid) { db.Entry(resident).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(resident)); }
public ActionResult Edit([Bind(Include = "ID,HomeID,FirstName,LastName")] Resident resident) { if (ModelState.IsValid) { try { db.Entry(resident).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system admin"); } } ViewBag.HomeID = new SelectList(db.Homes, "ID", "ID", resident.HomeID); return(View(resident)); }
public ActionResult Edit([Bind(Include = "ID,HomeID,Photo,AltText")] Graphic graphic) { if (ModelState.IsValid) { try { db.Entry(graphic).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "Unaable to save changes. Try again and if the problem persists contact your admin"); } } ViewBag.HomeID = new SelectList(db.Homes, "ID", "ID", graphic.HomeID); return(View(graphic)); }
public ActionResult EditPost(int?id, int?fromPage, string[] selectedCampaigns, bool?Readmit, string readmitDate, bool?AdmitEmergencyShelter, string updatedAdmitDate) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Resident residentToUpdate = db.Residents .Include(c => c.MilitaryCampaigns) .Include(b => b.Benefit) .Include(r => r.Referral) .Where(c => c.ResidentID == id) .Single(); ViewBag.DischargeInfo = residentToUpdate.ProgramEvents .Where(i => i.ProgramType.EventType == EnumEventType.DISCHARGE) .OrderByDescending(i => i.ProgramEventID).FirstOrDefault(); var lastEmergencyShelter = residentToUpdate.ProgramEvents.LastOrDefault(i => i.ProgramType.EventType == EnumEventType.ADMISSION && i.ProgramTypeID == 1); var lastAdmission = residentToUpdate.ProgramEvents.Any(i => i.ProgramType.EventType == EnumEventType.ADMISSION && i.ProgramTypeID == 2); ViewBag.EmergencyShelterTrack = lastEmergencyShelter != null && !lastAdmission; ViewBag.StateTerritoryID = new SelectList(db.States, "StateTerritoryID", "StateTerritoryID", residentToUpdate.StateTerritoryID); ViewBag.ReferralID = new SelectList(db.Referrals, "ReferralID", "ReferralName", residentToUpdate.ReferralID); ViewBag.Campaigns = residentService.PopulateAssignedCampaignData(residentToUpdate, db).OrderBy(i => i.MilitaryCampaign).ToList(); if (TryUpdateModel(residentToUpdate, "", new string[] { "ClearLastName", "ClearFirstMidName", "Gender", "Religion", "Ethnicity", "StateTerritoryID", "ReferralID", "AgeAtRelease", "OptionalReferralDescription", "StateTerritoryOther", "ClearBirthdate", "ServiceBranch", "NGReserve", "Note", "InVetCourt", "IsNoncombat", "Benefit", "MilitaryCampaigns", "TotalBenefitAmount" })) { try { UpdateResidentCampaigns(selectedCampaigns, residentToUpdate); /** for admitting a resident that had been previously an emergency shelter admittance */ if (lastEmergencyShelter != null && AdmitEmergencyShelter == true) { if (!string.IsNullOrEmpty(updatedAdmitDate)) { var newAdmitDate = DateTime.Parse(updatedAdmitDate, CultureInfo.InvariantCulture); lastEmergencyShelter.ClearEndDate = newAdmitDate; residentToUpdate.ProgramEvents.Add(new ProgramEvent { ProgramTypeID = 2, ClearStartDate = newAdmitDate }); residentToUpdate.IsCurrent = true; } } if (Readmit.HasValue) { if (Readmit == true) { if (string.IsNullOrEmpty(readmitDate)) { ModelState.AddModelError("", "Readmission Date is required if you are readmitting this resident."); return(View(residentToUpdate)); } var date = DateTime.Parse(readmitDate, CultureInfo.InvariantCulture); var ev = residentToUpdate.ProgramEvents .LastOrDefault(i => i.ProgramType.EventType == EnumEventType.DISCHARGE); // Emergency Discharge to be readmited. if (date < ev.ClearStartDate) { ModelState.AddModelError("", "Readmission date cannot be prior to last discharge date, " + ev.ClearStartDate.ToShortDateString()); return(View(residentToUpdate)); } ev.ClearEndDate = date; residentToUpdate.AgeAtRelease = 0; // reset the age at release for the readmitted resident. db.Entry(ev).State = EntityState.Modified; var readmitEvent = new ProgramEvent { ProgramTypeID = 3, ClearStartDate = date }; residentToUpdate.IsCurrent = true; residentToUpdate.ProgramEvents.Add(readmitEvent); } } db.SaveChanges(); TempData["UserMessage"] = residentToUpdate.ClearLastName + " has been updated. "; return(RedirectToAction("Index", new { page = fromPage })); } catch (DataException dex) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError(dex.Message, "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } residentToUpdate.FromPage = fromPage; return(View(residentToUpdate)); }
public ActionResult Manage(int ResidentID, CustomEvent model, int?fromPage = 1) { if (model != null) { IEnumerable <TempProgramEvent> newPrograms = model.ProgramEvents.Where(s => s.ProgramEventID == 0 && s.ProgramTypeID > 0); var idList = model.EnrolledTracks.Select(i => i.ProgramEventID).ToArray(); var peList = db.ProgramEvents .Join(idList, pe => pe.ProgramEventID, id => id, (pe, id) => pe) .ToList(); foreach (var track in model.EnrolledTracks) { var pe = peList.Single(i => i.ProgramEventID == track.ProgramEventID); pe.ClearEndDate = track.EndDate; pe.Completed = track.Completed; db.Entry(pe).State = EntityState.Modified; } foreach (TempProgramEvent track in newPrograms) { if (track.StartDate.Year < 2012 || (track.EndDate.HasValue && track.EndDate.Value.Year < 2012)) { TempData["UserMessage"] = "CRITICAL: Dates for " + track.StartDate.ToShortDateString() + " and " + track.EndDate?.ToShortDateString() + " cannot be before 2012."; return(RedirectToAction("Manage", new RouteValueDictionary( new { controller = "ProgramEvents", action = "Manage", Id = ResidentID, FromPage = fromPage }))); } if (track.EndDate.HasValue && track.EndDate.Value < track.StartDate) { TempData["UserMessage"] = "CRITICAL: Dates for " + track.StartDate.ToShortDateString() + " and " + track.EndDate?.ToShortDateString() + " -- start date cannot come after the end date."; return(RedirectToAction("Manage", new RouteValueDictionary( new { controller = "ProgramEvents", action = "Manage", Id = ResidentID, FromPage = fromPage }))); } if (ModelState.IsValid) { db.ProgramEvents.Add(new ProgramEvent { ResidentID = ResidentID, ProgramTypeID = track.ProgramTypeID, ClearStartDate = track.StartDate, ClearEndDate = track.EndDate, Completed = track.Completed }); } if (newPrograms.Count() > 1) { TempData["UserMessage"] = db.Residents.Find(ResidentID).Fullname + " has new tracks. "; db.SaveChanges(); } else if (newPrograms.Count() == 1) { TempData["UserMessage"] = db.Residents.Find(ResidentID).Fullname + " has a new track. "; db.SaveChanges(); } else { TempData["UserMessage"] = db.Residents.Find(ResidentID).Fullname + " was not enrolled in any new tracks. "; } var admitDischargeGroup = new SelectListGroup { Name = "Admit / Discharge " }; var otherTrackGroup = new SelectListGroup { Name = "Tracks to Success" }; ViewBag.ProgramTypeID = new SelectList(db.ProgramTypes.Where(t => t.EventType != EnumEventType.SYSTEM).ToList().OrderBy(i => (int)i.EventType).Select(i => new SelectListItem { Text = i.ProgramDescription, Value = i.ProgramTypeID.ToString(CultureInfo.InvariantCulture), Group = (i.EventType == EnumEventType.ADMISSION || i.EventType == EnumEventType.DISCHARGE) && i.EventType != EnumEventType.SYSTEM ? admitDischargeGroup : otherTrackGroup }).OrderBy(i => i.Group.Name).ToList(), "Value", "Text", "Group.Name", -1); } // We need to know the last track if the resident has been readmitted / discharged. As of now, position of admits/discharge tracks in list is not enforced. var resident = db.Residents.Find(ResidentID); foreach (var item in newPrograms) { if (item != null) { if (item.ProgramTypeID == 2 || item.ProgramTypeID == 3) { resident.IsCurrent = true; } if (item.ProgramTypeID == 1 || item.ProgramTypeID == 4 || item.ProgramTypeID == 5 || item.ProgramTypeID == 6 || item.ProgramTypeID == 7 || item.ProgramTypeID == 13 || item.ProgramTypeID == 2187) /* discharge types in db also includes ID == 1 which is an emergency shelter that is the exception */ { resident.IsCurrent = false; } } } db.SaveChanges(); } TempData["UserMessage"] = "Track information updated. "; return(RedirectToAction("Manage", new RouteValueDictionary( new { controller = "ProgramEvents", action = "Manage", Id = ResidentID, FromPage = fromPage }))); }