public IActionResult Create(HouseholdProfileCreateModel householdProfileCreateModel) { try { if (ModelState.IsValid) { var householdProfile = new HouseholdProfile(); householdProfile.ProfileId = householdProfileCreateModel.ProfileId; householdProfile.Address = householdProfileCreateModel.Address; householdProfile.BarangayId = householdProfileCreateModel.BarangayId; householdProfile.Note = householdProfileCreateModel.Note; householdProfile.DateCreated = DateTime.Now; householdProfile.DateTimeLastUpdated = householdProfile.DateCreated; _householdProfile.Add(householdProfile); return(RedirectToAction("Index")); } return(View(householdProfileCreateModel)); } catch (Exception err) { ModelState.AddModelError(err.ToString(), "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(householdProfileCreateModel)); }
public IActionResult Details(long id) { HouseholdProfile household = _householdProfile.GetById(id); List <HouseholdMember> members = _householdMembers.GetAllByHouseholdProfileId(household.Id).ToList(); IEnumerable <HouseholdMemberDetailModel> householdMembersDetailModel = members .Select(hm => new HouseholdMemberDetailModel { Id = hm.PersonId, FullName = hm.Person.FirstName + " " + hm.Person.MiddleName + " " + hm.Person.LastName, Sex = hm.Person.Sex.ToString(), RelationToHead = hm.RelationToHead.ToString(), YearsOld = 0, MonthsOld = 0, DaysOld = 0 }).ToList(); var model = new HouseholdProfileDetailModel() { Id = household.Id, ProfileId = household.ProfileId, Address = household.Address, Barangay = household.Barangay.Name, Note = household.Note, HouseholdMembers = householdMembersDetailModel }; return(View(model)); }
// GET: HouseholdProfiles/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HouseholdProfile householdProfile = db.HouseholdProfiles.Find(id); if (householdProfile == null) { return(HttpNotFound()); } return(View(householdProfile)); }
public ActionResult Create([Bind(Include = "Id,HouseholdProfileID,FourPsCCTBeneficiary,Address,BarangayID,PersonId,Note")] HouseholdProfile householdProfile) { if (ModelState.IsValid) { db.HouseholdProfiles.Add(householdProfile); db.SaveChanges(); return(RedirectToAction("Index")); } var NonHouseholdMemberPatients = db.Patient.Where(y => y.HouseholdProfileID == null || y.HouseholdProfileID == "").ToList(); ViewBag.PersonID = new SelectList(NonHouseholdMemberPatients, "PersonID", "FullName", householdProfile.PersonID); ViewBag.BarangayId = new SelectList(db.Barangays, "BarangayID", "Name", householdProfile.BarangayID); return(View(householdProfile)); }
public ActionResult DeleteConfirmed(int id) { HouseholdProfile householdProfile = db.HouseholdProfiles.Find(id); var householdMembers = db.Patient.Where(y => y.HouseholdProfileID == householdProfile.HouseholdProfileID).ToList(); foreach (Person patient in householdMembers) { patient.HouseholdProfileID = null; db.Entry(patient).State = EntityState.Modified; } db.HouseholdProfiles.Remove(householdProfile); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,HouseholdProfileID,FourPsCCTBeneficiary,Address,BarangayID,PersonId,Note")] HouseholdProfile householdProfile) { if (ModelState.IsValid) { db.Entry(householdProfile).State = EntityState.Modified; //Person person = db.Patient.Find(householdProfile.PersonID); //person. db.SaveChanges(); return(RedirectToAction("Index")); } var NonHouseholdMemberPatients = db.Patient.Where(y => y.HouseholdProfileID == null || y.HouseholdProfileID == "" || y.HouseholdProfileID == householdProfile.HouseholdProfileID); ViewBag.PersonID = new SelectList(NonHouseholdMemberPatients, "PersonID", "FullName", householdProfile.PersonID); ViewBag.BarangayId = new SelectList(db.Barangays, "BarangayID", "Name", householdProfile.BarangayID); return(View(householdProfile)); }
// GET: HouseholdProfiles/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HouseholdProfile householdProfile = db.HouseholdProfiles.Find(id); if (householdProfile == null) { return(HttpNotFound()); } var NonHouseholdMemberPatients = db.Patient.Where(y => y.HouseholdProfileID == null || y.HouseholdProfileID == "" || y.HouseholdProfileID == householdProfile.HouseholdProfileID); ViewBag.PersonID = new SelectList(NonHouseholdMemberPatients, "PersonID", "FullName", householdProfile.PersonID); ViewBag.BarangayId = new SelectList(db.Barangays, "BarangayID", "Name", householdProfile.BarangayID); return(View(householdProfile)); }
public IActionResult Edit(int id) { HouseholdProfile household = _householdProfile.GetById(id); List <Barangay> barangaylist = new List <Barangay>(); barangaylist = (from barangay in _barangay.GetAll() select barangay).ToList(); barangaylist.Insert(0, new Barangay { Id = 0, Name = "Select" }); ViewBag.ListOfBarangay = barangaylist; var householdProfileEditModel = new HouseholdProfileEditModel() { Id = household.Id, ProfileId = household.ProfileId, Address = household.Address, BarangayId = household.BarangayId, Note = household.Note }; return(View(householdProfileEditModel)); }
public IActionResult Edit(HouseholdProfileEditModel householdProfileEditModel) { try { if (ModelState.IsValid) { var updatedHousehold = new HouseholdProfile(); updatedHousehold.Id = householdProfileEditModel.Id; updatedHousehold.ProfileId = householdProfileEditModel.ProfileId; updatedHousehold.Address = householdProfileEditModel.Address; updatedHousehold.BarangayId = householdProfileEditModel.BarangayId; updatedHousehold.Note = householdProfileEditModel.Note; _householdProfile.Update(updatedHousehold); return(RedirectToAction("Index")); } return(View(householdProfileEditModel)); } catch (Exception err) { ModelState.AddModelError(err.ToString(), "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(householdProfileEditModel)); }
public void Update(HouseholdProfile updatedHouseholdProfile) { _context.Entry(updatedHouseholdProfile).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(HouseholdProfile newHouseholdProfile) { _context.Add(newHouseholdProfile); _context.SaveChanges(); }