public ActionResult Generate(int id) { string userId = User.Identity.GetUserId(); CustomerBillingInformation customerBillingInformations = db.CustomerBillingInformations.Where(find => find.CustomerPolicyRecordId == id).FirstOrDefault(); return(View(customerBillingInformations)); }
public ActionResult DeleteConfirmed(int id) { CustomerBillingInformation customerBillingInformation = db.CustomerBillingInformations.Find(id); db.CustomerBillingInformations.Remove(customerBillingInformation); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,BillNumber,GetCustomerPolicyRecordId")] CustomerBillingInformation customerBillingInformation) { if (ModelState.IsValid) { db.Entry(customerBillingInformation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GetCustomerPolicyRecordId = new SelectList(db.CustomerPolicyRecords, "Id", "ApplicationUserId", customerBillingInformation.CustomerPolicyRecordId); return(View(customerBillingInformation)); }
// GET: CustomerBillingInformations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustomerBillingInformation customerBillingInformation = db.CustomerBillingInformations.Find(id); if (customerBillingInformation == null) { return(HttpNotFound()); } return(View(customerBillingInformation)); }
// GET: CustomerBillingInformations/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustomerBillingInformation customerBillingInformation = db.CustomerBillingInformations.Find(id); if (customerBillingInformation == null) { return(HttpNotFound()); } ViewBag.GetCustomerPolicyRecordId = new SelectList(db.CustomerPolicyRecords, "Id", "ApplicationUserId", customerBillingInformation.CustomerPolicyRecordId); return(View(customerBillingInformation)); }
public ActionResult Create([Bind(Include = "Id,ApplicationUserId,PolicyNumber,VehicleInformationId,PolicyTypeId,PolicyDate,Tracker")] CustomerPolicyRecord customerPolicyRecord) { var searchData = db.CustomerPolicyRecords.Where(find => find.VehicleInformationId == customerPolicyRecord.VehicleInformationId).Count(); if (searchData == 0) { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated == true) { customerPolicyRecord.PolicyDate = DateTime.Now; var store = new UserStore <ApplicationUser>(new ApplicationDbContext()); var userManager = new UserManager <ApplicationUser>(store); ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result; Random generator = new Random(); String generated_code = ""; var estimateCodes = from item in db.Estimates select item; bool quit = false; while (quit != true) { generated_code = generator.Next(0, 999999).ToString("D6"); if (estimateCodes.Count() == 0) { quit = true; ViewBag.Code = "E-" + generated_code; } else { foreach (var item in estimateCodes) { if (generated_code != item.EstimateNumber) { ViewBag.Code = "E-" + generated_code; quit = true; } } } } customerPolicyRecord.PolicyNumber = generated_code; customerPolicyRecord.ApplicationUserId = user.Id; db.CustomerPolicyRecords.Add(customerPolicyRecord); db.SaveChanges(); int bill_id = db.CustomerPolicyRecords.Count() + 1; bill_id -= 1; generated_code = generator.Next(0, 999999).ToString("D6"); CustomerBillingInformation billingInformation = new CustomerBillingInformation() { CustomerPolicyRecordId = bill_id, BillNumber = "B-" + generated_code, }; db.CustomerBillingInformations.Add(billingInformation); db.SaveChanges(); TempData["id"] = customerPolicyRecord.Id; return(Redirect("/CustomerPolicyRecords/Details/" + customerPolicyRecord.Id)); } else { return(RedirectToAction("Login", "Account")); } } } else { ViewBag.SameVehiclePolicyError = "Already applied with current vehicle"; } ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Name", customerPolicyRecord.ApplicationUserId); ViewBag.PolicyTypeId = new SelectList(db.PolicyTypes, "PolicyTypeId", "Type", customerPolicyRecord.PolicyTypeId); ViewBag.VehicleInformationId = new SelectList(db.VehicleInformations, "VehicleInformationId", "VehicleCompany", customerPolicyRecord.VehicleInformationId); return(View(customerPolicyRecord)); }