public ActionResult Promote(int?oParId) { //get the old president and change to false and remove them from the hierarchy OfficerPartner presidents = ent.OfficerPartners.Where(m => m.IsPresident == true).FirstOrDefault(); if (presidents != null) { presidents.IsPresident = false; ent.Entry(presidents).State = System.Data.Entity.EntityState.Modified; ent.SaveChanges(); //if the president is done, meaning they are not officers anymore OfficerHierarchy hierarchy = ent.OfficerHierarchies.Where(m => m.OParId == presidents.OParId).FirstOrDefault(); ent.OfficerHierarchies.Remove(hierarchy); ent.SaveChanges(); } OfficerPartner newPresidents = ent.OfficerPartners.Where(m => m.OParId == oParId).FirstOrDefault(); newPresidents.IsPresident = true; ent.Entry(newPresidents).State = System.Data.Entity.EntityState.Modified; ent.SaveChanges(); return(RedirectToAction("PromotePresident")); }
public ActionResult DisplayCreateOfficer(string maleId, string femaleId) { if (maleId == null && femaleId == null) { return(View()); } OfficerPartner partner = new OfficerPartner() { UserIdMale = maleId, UserIdFemale = femaleId, IsPresident = false }; ent.OfficerPartners.Add(partner); ent.SaveChanges(); //instead of incrementing, the new OParId is used as the rank basis. It is asured that the new id will be the highest //higher the rank means the pair is new officers int?highestRank = partner.OParId; ent.OfficerHierarchies.Add( new OfficerHierarchy() { OParId = partner.OParId, Rank = (int)highestRank } ); ent.SaveChanges(); return(RedirectToAction("DisplayCreateOfficer")); }