Example #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CustomerPolicyRecord customerPolicyRecord = db.CustomerPolicyRecords.Find(id);

            db.CustomerPolicyRecords.Remove(customerPolicyRecord);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "Id,ApplicationUserId,PolicyNumber,VehicleInformationId,PolicyTypeId,PolicyDate,Tracker")] CustomerPolicyRecord customerPolicyRecord)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerPolicyRecord).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ApplicationUserId    = new SelectList(db.ApplicationUsers, "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));
 }
Example #3
0
        // GET: CustomerPolicyRecords/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerPolicyRecord customerPolicyRecord = db.CustomerPolicyRecords.Find(id);

            if (customerPolicyRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(customerPolicyRecord));
        }
Example #4
0
        // GET: CustomerPolicyRecords/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerPolicyRecord customerPolicyRecord = db.CustomerPolicyRecords.Find(id);

            if (customerPolicyRecord == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ApplicationUserId    = new SelectList(db.ApplicationUsers, "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));
        }
Example #5
0
        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));
        }