public ActionResult BuyPolicy(VerifyPolicy verify) { if (!verify.Acknowledge) { ModelState.AddModelError("", "Please e-sign to buy policy."); return(View(verify)); } if (!DateTime.TryParse(verify.PolicyStartDate, out DateTime startDate)) { return(View(verify)); } Policy p = new Policy { PolicyEffDate = startDate.ToString("yyyy-MM-dd"), PolicyEndDate = startDate.AddYears(1).ToString("yyyy-MM-dd"), QuoteId = (int)Session["quoteId"], PolicyKey = Session["quoteId"].ToString() + "_1", PolicyStatus = startDate <= DateTime.Now ? "ACTIVE" : "PENDING", PolicyTerm = 1 }; using (QuotesEntity qe = new QuotesEntity()) { qe.Policies.Add(p); qe.SaveChanges(); } Session["policyId"] = p.Id; return(RedirectToAction("Confirmation")); }
public ActionResult CancelPolicy(int?policyId) { using (QuotesEntity qe = new QuotesEntity()) { Policy p = qe.Policies.FirstOrDefault(pp => pp.Id == policyId); if (p == null) { return(UserPolicies()); } p.PolicyTerm = 0; p.PolicyStatus = "CANCELLED"; qe.SaveChanges(); Session["policyId"] = p.Id; return(RedirectToAction("Confirmation", "Policy")); } }
public ActionResult BuyPolicy(VerifyPolicy verify) { if (!verify.Acknowledge) { ModelState.AddModelError("", "Please e-sign to buy policy."); return(View(verify)); } if (!DateTime.TryParse(verify.PolicyStartDate, out DateTime startDate)) { return(View(verify)); } //Added to check validation of model if (!ModelState.IsValid) { return(View(verify)); } //Moved this block into an else statement so when all validity checks return w/o problem, // this will execute and send user to Confirmation page. else { Policy p = new Policy { PolicyEffDate = startDate.ToString("yyyy-MM-dd"), PolicyEndDate = startDate.AddYears(1).ToString("yyyy-MM-dd"), QuoteId = (int)Session["quoteId"], PolicyKey = Session["quoteId"].ToString() + "_1", PolicyStatus = startDate <= DateTime.Now ? "ACTIVE" : "PENDING", PolicyTerm = 1 }; using (QuotesEntity qe = new QuotesEntity()) { qe.Policies.Add(p); qe.SaveChanges(); } Session["policyId"] = p.Id; return(RedirectToAction("Confirmation")); } }
public ActionResult NewUser(NewUser newUser) { if (!ModelState.IsValid) { return(View("NewUser", newUser)); } using (QuotesEntity qe = new QuotesEntity()) { User u = qe.Users.FirstOrDefault(model => model.Username == newUser.Username); if (u != null) { ModelState.AddModelError("", "This username already exists."); return(View("NewUser", newUser)); } User user = new User(newUser); qe.Users.Add(user); qe.SaveChanges(); return(RedirectUser(user)); }; }
public ActionResult SaveQuote() { Quote quote = Session["Quote"] as Quote; Property property = Session["Property"] as Property; Location location = Session["Location"] as Location; Homeowner homeowner = Session["Homeowner"] as Homeowner; User user = Session["User"] as User; quote.Property = property; property.Location = location; location.Homeowner = homeowner; homeowner.UserId = user.Id; using (QuotesEntity qe = new QuotesEntity()) { qe.Quotes.Add(quote); qe.SaveChanges(); } Session.Clear(); Session["User"] = user; return(RedirectToAction("QuoteDetails")); }