public ActionResult Status(int?id) { Household household = db.Households.Find(id); string stat = null; bool new_stat = true; if (household.IsExcluded) { stat = "Active."; new_stat = false; } else { stat = "Excluded."; new_stat = true; } HouseholdHistory hh = new HouseholdHistory(); hh.HouseholdId = household.HouseholdId; hh.CreatedByUsername = User.Identity.Name; hh.CreatedBy = User.Identity.GetFullName(); hh.Body = "changed the status to " + stat; hh.DateTimeCreated = DateTime.UtcNow.AddHours(8); db.HouseholdHistory.Add(hh); household.IsExcluded = new_stat; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "PersonId,GivenName,MiddleName,LastName,IsBeneficiary,IsGrantee,IsParentLeader,Gender,picture_url,IsExcluded,BirthDate,DateTimeCreated,HouseholdId,SchoolId,HospitalId,OccupationId,EducationalAttainmentId,RelationToGranteeId")] Person person) { int admin_city = Convert.ToInt16(User.Identity.GetCityId()); if (person.IsGrantee == true) { var check_grantee = db.Persons.FirstOrDefault(p => p.IsGrantee == true && p.HouseholdId == person.HouseholdId); if (check_grantee != null) { ViewBag.EducationalAttainmentId = new SelectList(db.EducationalAttainemnts, "EducationalAttainmentId", "Name"); ViewBag.HospitalId = new SelectList(db.Hospitals.Where(s => s.CityId == admin_city), "HospitalId", "Name"); ViewBag.OccupationId = new SelectList(db.Occupations, "OccupationId", "Name"); ViewBag.RelationToGranteeId = new SelectList(db.RelationToGrantees, "RelationToGranteeId", "Name"); ViewBag.SchoolId = new SelectList(db.Schools.Where(s => s.CityId == admin_city), "SchoolId", "Name"); ModelState.AddModelError(string.Empty, "A grantee already exists in this household; " + check_grantee.getFullName()); return(View(person)); } } person.DateTimeCreated = DateTime.UtcNow.AddHours(8); if (ModelState.IsValid) { HouseholdHistory hh = new HouseholdHistory(); hh.HouseholdId = person.HouseholdId; hh.CreatedByUsername = User.Identity.Name; hh.CreatedBy = User.Identity.GetFullName(); hh.Body = "added member; " + person.getFullName() + "."; hh.DateTimeCreated = DateTime.UtcNow.AddHours(8); db.HouseholdHistory.Add(hh); db.Persons.Add(person); db.SaveChanges(); return(RedirectToAction("Details", "Households", new { id = person.HouseholdId })); } ViewBag.EducationalAttainmentId = new SelectList(db.EducationalAttainemnts, "EducationalAttainmentId", "Name"); ViewBag.HospitalId = new SelectList(db.Hospitals.Where(s => s.CityId == admin_city), "HospitalId", "Name"); ViewBag.OccupationId = new SelectList(db.Occupations, "OccupationId", "Name"); ViewBag.RelationToGranteeId = new SelectList(db.RelationToGrantees, "RelationToGranteeId", "Name"); ViewBag.SchoolId = new SelectList(db.Schools.Where(s => s.CityId == admin_city), "SchoolId", "Name"); return(View(person)); }
public ActionResult Edit([Bind(Include = "HouseholdId,Name,DateTimeCreated,IsExcluded,CityId")] Household household) { HouseholdHistory hh = new HouseholdHistory(); hh.HouseholdId = household.HouseholdId; hh.CreatedByUsername = User.Identity.Name; hh.CreatedBy = User.Identity.GetFullName(); hh.Body = "edited Household name to " + household.Name + "."; hh.DateTimeCreated = DateTime.UtcNow.AddHours(8); db.HouseholdHistory.Add(hh); if (ModelState.IsValid) { db.Entry(household).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } int city = Convert.ToInt16(User.Identity.GetCityId()); ViewBag.CityId = new SelectList(db.City.Where(c => c.CityId == city), "CityId", "Name"); return(View(household)); }