public ActionResult Create(Comm comm, string txtCharge, string txtConstitution) { if (!db.CommSuperAdmin.Any(csa => csa.SysUser_Email == User.Identity.Name && csa.StartDate <= DateTime.Today && (csa.EndDate ?? DateTime.MaxValue) >= DateTime.Today && csa.CommOwn_ID == comm.CommOwn_ID)) { return(RedirectToAction("login", "account", null)); } //make sure an active committee with the same name doesn't exist for this division already. if (db.Comm.Any(c => c.Name == comm.Name && c.CommOwn_ID == comm.CommOwn_ID && c.IsArchived == "N")) { ModelState.AddModelError("Name", "An active committee with this name already exists for this division"); return(View(comm)); } comm.CreatedDate = DateTime.Now; comm.CreatedBy = User.Identity.Name; comm.IsArchived = "N"; CommCharge commCharge = new CommCharge(); CommConstitution commCon = new CommConstitution(); if (ModelState.IsValid) { //save new committee so we can get the new autonumber for comm.ID db.Comm.Add(comm); db.SaveChanges(); // Start adding Committees Charges into the database commCharge.Comm_CommOwn_ID = comm.CommOwn_ID; commCharge.Comm_ID = comm.ID; commCharge.Charges = txtCharge; commCharge.CreatedBy = User.Identity.Name; commCharge.CreatedDate = DateTime.Now.Date; commCharge.EffectiveDate = comm.EffectiveDate; db.CommCharge.Add(commCharge); // Finish adding Committees Charges into the database // Start adding Committees Constitution into the database commCon.Comm_CommOwn_ID = comm.CommOwn_ID; commCon.Comm_ID = comm.ID; commCon.Constitution = txtConstitution; commCon.EffectiveDate = comm.EffectiveDate; commCon.CreatedDate = DateTime.Now.Date; commCon.CreatedBy = User.Identity.Name; db.CommConstitution.Add(commCon); // Finish adding Committees Constitution into the database db.SaveChanges(); //AuditLogController.Add("Add", User.Identity.Name, "New committee name: " + comm.Name + " is added"); //Not needed since created by/date is maintained by comm return(RedirectToAction("details", "committees", new { primaryKey1 = comm.CommOwn_ID, primaryKey2 = comm.ID })); } return(View(comm)); }
public ActionResult Edit(int primaryKey1, int primaryKey2) { //get commCharge with newest effective date CommCharge commcharge = db.CommCharge.Where(cc => cc.Comm_CommOwn_ID == primaryKey1 && cc.Comm_ID == primaryKey2) .OrderByDescending(cc => cc.EffectiveDate).First(); if (commcharge == null) { return(HttpNotFound()); } return(View(commcharge)); }
public ActionResult Edit(int primaryKey1, int primaryKey2, CommCharge commcharge) { //get charge from database. //compare for changes. //make new charge //add to database. if (db.CommConstitution.Any(cc => cc.EffectiveDate == commcharge.EffectiveDate)) { ModelState.AddModelError("EffectiveDate", "Charges with this effective date already exist."); return(View(commcharge)); } CommCharge oldCommCharge = db.CommCharge.Where(cc => cc.Comm_CommOwn_ID == primaryKey1 && cc.Comm_ID == primaryKey2) .OrderByDescending(cc => cc.EffectiveDate).First(); if (commcharge.EffectiveDate > DateTime.Now) { ModelState.AddModelError("EffectiveDate", "Effective date may not occur in the future."); } if (!ModelState.IsValid) { return(View(commcharge)); } if (oldCommCharge.Charges == commcharge.Charges && oldCommCharge.EffectiveDate == commcharge.EffectiveDate) { //no change return(RedirectToAction("details", "committees", new { primaryKey1, primaryKey2 })); } else { CommCharge newCommCharge = new CommCharge(); newCommCharge.Charges = commcharge.Charges; newCommCharge.CreatedBy = User.Identity.Name; newCommCharge.CreatedDate = DateTime.Today; newCommCharge.EffectiveDate = commcharge.EffectiveDate; newCommCharge.Comm_CommOwn_ID = primaryKey1; newCommCharge.Comm_ID = primaryKey2; db.CommCharge.Add(newCommCharge); db.SaveChanges(); return(RedirectToAction("details", "committees", new { primaryKey1, primaryKey2 })); } }