public ActionResult LastDayRequest(LastDay lastDay) { lastDay.Validate(ModelState, User); //if (db.LastDays.Any(x => x.EmailAddress == lastDay.EmailAddress)) //{ // ModelState.AddModelError("Request", "Last Day Already Requested"); //} if (ModelState.IsValid) { LastDayNotice lastDayNotice = new LastDayNotice(lastDay, "New"); if (TryValidateModel(lastDayNotice) == true) { if (lastDay.Immediate == true) { lastDay.Decommission(); } else { if (db.GSCUsers.Any(x => x.GUID == lastDay.GUID && x.Active == true)) { foreach (GSCUser gscUser in db.GSCUsers.Where(x => x.GUID == lastDay.GUID && x.Active == true)) { var gscClient = db.GSCClients.Find(gscUser.GSCClientID); gscUser.GSCClient = gscClient; gscUser.EndDate = lastDay.EndDate; gscUser.MailExternalCompany(); } } } if (lastDay.Suppress == false) { Mailer mailer = new Mailer(MessageTemplate.LastDayEmployee, true); if (lastDay.IsContingent == true) { mailer = new Mailer(MessageTemplate.LastDayContingent, true); } mailer.SetFromAddress(lastDay.RequestersEmail); mailer.AddRecipient(lastDay.ManagersEmail); if (lastDay.ITaaS == true) { mailer.AddITaaSNotificationGroup(); } mailer.SendMessage("LastDayNotice", lastDayNotice, lastDayNotice.Subject); } db.LastDays.Add(lastDay); db.SaveChanges(); return(RedirectToAction("Index")); } ModelState.AddModelError("MailNotice", "Mail Notice Error"); } return(View(lastDay)); }