public void SaveSummaryVehicleDetails(SummaryVehicleDetail SummaryVehicleDetail)
 {
     InsuranceContext.SummaryVehicleDetails.Insert(SummaryVehicleDetail);
 }
        public async Task <ActionResult> SubmitPlan(WebCustomerModel model)
        {
            SummaryDetailService servicedetail = new SummaryDetailService();

            Insurance.Service.ICEcashService ICEcashService = new Insurance.Service.ICEcashService();
            List <RiskDetailModel>           list           = new List <RiskDetailModel>();
            string PartnerToken = "";



            #region Add All info to database

            //var vehicle = (RiskDetailModel)Session["VehicleDetail"];
            Session["SummaryDetailed"] = model;
            string SummeryofReinsurance    = "";
            string SummeryofVehicleInsured = "";
            bool   userLoggedin            = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
            var    customer = model.Customer;

            // defualt value for customer
            customer.Zipcode = "00263";
            customer.Country = "+263";

            var userDetial = UserManager.FindByEmail(customer.EmailAddress);

            if (userDetial == null)
            {
                if (customer != null)
                {
                    decimal custId = 0;
                    var     user   = new ApplicationUser {
                        UserName = customer.EmailAddress, Email = customer.EmailAddress, PhoneNumber = customer.PhoneNumber
                    };
                    var result = await UserManager.CreateAsync(user, "Geninsure@123");

                    SaveUserPasswordDetails(user);
                    if (result.Succeeded)
                    {
                        var roleresult  = UserManager.AddToRole(user.Id, "Web Customer"); // for web user
                        var objCustomer = InsuranceContext.Customers.All().OrderByDescending(x => x.Id).FirstOrDefault();
                        if (objCustomer != null)
                        {
                            custId = objCustomer.CustomerId + 1;
                        }
                        else
                        {
                            custId = Convert.ToDecimal(ConfigurationManager.AppSettings["CustomerId"]);
                        }

                        customer.UserID      = user.Id;
                        customer.CustomerId  = custId;
                        customer.CountryCode = "+263";
                        var customerdata = Mapper.Map <CustomerModel, Customer>(customer);
                        InsuranceContext.Customers.Insert(customerdata);
                        customer.Id = customerdata.Id;
                    }
                }
            }
            else
            {
                var customerDetails = InsuranceContext.Customers.Single(where : "UserID='" + userDetial + "'");
                customerDetails.FirstName    = customer.FirstName;
                customerDetails.LastName     = customer.LastName;
                customerDetails.PhoneNumber  = customer.PhoneNumber;
                customerDetails.AddressLine1 = customerDetails.AddressLine1;
                InsuranceContext.Customers.Update(customerDetails); // 13_june_2019
                customer.Id = customerDetails.Id;
            }



            // get policy details
            var policy = ProductDetail();
            if (policy != null)
            {
                policy.CustomerId      = customer.Id;
                policy.StartDate       = null;
                policy.EndDate         = null;
                policy.TransactionDate = null;
                policy.RenewalDate     = null;
                policy.RenewalDate     = null;
                policy.StartDate       = null;
                policy.TransactionDate = null;
                policy.CreatedBy       = customer.Id;
                policy.CreatedOn       = DateTime.Now;
                InsuranceContext.PolicyDetails.Insert(policy);
            }

            var Id = 0;
            var listReinsuranceTransaction = new List <ReinsuranceTransaction>();

            // defualt value for vehicle
            model.RiskDetail.CurrencyId        = 6; //default "RTGS$" select
            model.RiskDetail.NoOfCarsCovered   = 1;
            model.RiskDetail.AgentCommissionId = 1;


            List <RiskDetailModel> vehilceList = new List <RiskDetailModel>();
            vehilceList.Add(model.RiskDetail);

            var    vehicle   = vehilceList;
            string format    = "yyyyMMdd";
            int    vehicleId = 0;

            if (vehicle != null && vehicle.Count > 0)
            {
                foreach (var item in vehicle.ToList())
                {
                    if (!string.IsNullOrEmpty(item.LicExpiryDate))
                    {
                        var LicExpiryDate = DateTime.ParseExact(item.LicExpiryDate, format, CultureInfo.InvariantCulture);
                        item.LicExpiryDate = LicExpiryDate.ToShortDateString();
                        if (item.VehicleLicenceFee > 0)
                        {
                            item.IceCashRequest = "InsuranceAndLicense";
                        }
                    }
                    else
                    {
                        item.IceCashRequest = "Insurance";
                    }

                    if (item.RadioLicenseCost > 0)  // for now
                    {
                        item.IncludeRadioLicenseCost = true;
                    }

                    if (!string.IsNullOrEmpty(item.LicenseDeliveryWay))
                    {
                        item.IsLicenseDiskNeeded = true;
                    }



                    var _item = item;

                    if (_item.Id == 0)
                    {
                        var service = new RiskDetailService();
                        _item.CustomerId     = customer.Id;
                        _item.PolicyId       = policy.Id;
                        _item.CoverStartDate = DateTime.Now;
                        _item.Id             = service.AddVehicleInformation(_item);
                        vehicleId            = _item.Id;

                        // Delivery Address Save
                        var LicenseAddress = new LicenceDiskDeliveryAddress();
                        LicenseAddress.Address1   = _item.LicenseAddress1;
                        LicenseAddress.Address2   = _item.LicenseAddress2;
                        LicenseAddress.City       = _item.LicenseCity;
                        LicenseAddress.VehicleId  = _item.Id;
                        LicenseAddress.CreatedBy  = customer.Id;
                        LicenseAddress.CreatedOn  = DateTime.Now;
                        LicenseAddress.ModifiedBy = customer.Id;
                        LicenseAddress.ModifiedOn = DateTime.Now;

                        InsuranceContext.LicenceDiskDeliveryAddresses.Insert(LicenseAddress);

                        ///Licence Ticket
                        if (_item.IsLicenseDiskNeeded)
                        {
                            var LicenceTicket = new LicenceTicket();
                            var Licence       = InsuranceContext.LicenceTickets.All(orderBy: "Id desc").FirstOrDefault();
                            if (Licence != null)
                            {
                                string number = Licence.TicketNo.Substring(3);

                                long   tNumber  = Convert.ToInt64(number) + 1;
                                string TicketNo = string.Empty;
                                int    length   = 6;
                                length = length - tNumber.ToString().Length;

                                for (int i = 0; i < length; i++)
                                {
                                    TicketNo += "0";
                                }
                                TicketNo += tNumber;
                                var ticketnumber = "GEN" + TicketNo;

                                LicenceTicket.TicketNo = ticketnumber;
                            }
                            else
                            {
                                var TicketNo = ConfigurationManager.AppSettings["TicketNo"];
                                LicenceTicket.TicketNo = TicketNo;
                            }

                            LicenceTicket.VehicleId      = _item.Id;
                            LicenceTicket.CloseComments  = "";
                            LicenceTicket.ReopenComments = "";
                            LicenceTicket.DeliveredTo    = "";
                            LicenceTicket.CreatedDate    = DateTime.Now;
                            LicenceTicket.CreatedBy      = customer.Id;
                            LicenceTicket.IsClosed       = false;
                            LicenceTicket.PolicyNumber   = policy.PolicyNumber;
                            InsuranceContext.LicenceTickets.Insert(LicenceTicket);
                        }

                        ///Reinsurance

                        var ReinsuranceCases = InsuranceContext.Reinsurances.All(where : $"Type='Reinsurance'").ToList();
                        var ownRetention     = InsuranceContext.Reinsurances.All().Where(x => x.TreatyCode == "OR001").Select(x => x.MaxTreatyCapacity).SingleOrDefault();
                        var ReinsuranceCase  = new Reinsurance();

                        foreach (var Reinsurance in ReinsuranceCases)
                        {
                            if (Reinsurance.MinTreatyCapacity <= item.SumInsured && item.SumInsured <= Reinsurance.MaxTreatyCapacity)
                            {
                                ReinsuranceCase = Reinsurance;
                                break;
                            }
                        }

                        if (ReinsuranceCase != null && ReinsuranceCase.MaxTreatyCapacity != null)
                        {
                            var basicPremium      = item.Premium;
                            var ReinsuranceBroker = InsuranceContext.ReinsuranceBrokers.Single(where : $"ReinsuranceBrokerCode='{ReinsuranceCase.ReinsuranceBrokerCode}'");
                            var AutoFacSumInsured = 0.00m;
                            var AutoFacPremium    = 0.00m;
                            var FacSumInsured     = 0.00m;
                            var FacPremium        = 0.00m;

                            if (ReinsuranceCase.MinTreatyCapacity > 200000)
                            {
                                var autofaccase              = ReinsuranceCases.FirstOrDefault();
                                var autofacSumInsured        = autofaccase.MaxTreatyCapacity - ownRetention;
                                var autofacReinsuranceBroker = InsuranceContext.ReinsuranceBrokers.Single(where : $"ReinsuranceBrokerCode='{autofaccase.ReinsuranceBrokerCode}'");

                                var _reinsurance = new ReinsuranceTransaction();
                                _reinsurance.ReinsuranceAmount = autofacSumInsured;
                                AutoFacSumInsured = Convert.ToDecimal(_reinsurance.ReinsuranceAmount);
                                _reinsurance.ReinsurancePremium = Math.Round(Convert.ToDecimal((_reinsurance.ReinsuranceAmount / item.SumInsured) * basicPremium), 2);
                                AutoFacPremium = Convert.ToDecimal(_reinsurance.ReinsurancePremium);
                                _reinsurance.ReinsuranceCommissionPercentage = Convert.ToDecimal(autofacReinsuranceBroker.Commission);
                                _reinsurance.ReinsuranceCommission           = Math.Round(Convert.ToDecimal((_reinsurance.ReinsurancePremium * _reinsurance.ReinsuranceCommissionPercentage) / 100), 2);
                                _reinsurance.VehicleId           = item.Id;
                                _reinsurance.ReinsuranceBrokerId = autofacReinsuranceBroker.Id;
                                _reinsurance.TreatyName          = autofaccase.TreatyName;
                                _reinsurance.TreatyCode          = autofaccase.TreatyCode;
                                _reinsurance.CreatedOn           = DateTime.Now;
                                _reinsurance.CreatedBy           = customer.Id;

                                InsuranceContext.ReinsuranceTransactions.Insert(_reinsurance);

                                SummeryofReinsurance += "<tr><td>" + Convert.ToString(_reinsurance.Id) + "</td><td>" + ReinsuranceCase.TreatyCode + "</td><td>" + ReinsuranceCase.TreatyName + "</td><td>" + Convert.ToString(_reinsurance.ReinsuranceAmount) + "</td><td>" + Convert.ToString(ReinsuranceBroker.ReinsuranceBrokerName) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(_reinsurance.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(ReinsuranceBroker.Commission) + "</td></tr>";

                                listReinsuranceTransaction.Add(_reinsurance);

                                var __reinsurance = new ReinsuranceTransaction();
                                __reinsurance.ReinsuranceAmount = _item.SumInsured - ownRetention - autofacSumInsured;
                                FacSumInsured = Convert.ToDecimal(__reinsurance.ReinsuranceAmount);
                                __reinsurance.ReinsurancePremium = Math.Round(Convert.ToDecimal((__reinsurance.ReinsuranceAmount / item.SumInsured) * basicPremium), 2);
                                FacPremium = Convert.ToDecimal(__reinsurance.ReinsurancePremium);
                                __reinsurance.ReinsuranceCommissionPercentage = Convert.ToDecimal(ReinsuranceBroker.Commission);
                                __reinsurance.ReinsuranceCommission           = Math.Round(Convert.ToDecimal((__reinsurance.ReinsurancePremium * __reinsurance.ReinsuranceCommissionPercentage) / 100), 2);
                                __reinsurance.VehicleId           = item.Id;
                                __reinsurance.ReinsuranceBrokerId = ReinsuranceBroker.Id;
                                __reinsurance.TreatyName          = ReinsuranceCase.TreatyName;
                                __reinsurance.TreatyCode          = ReinsuranceCase.TreatyCode;
                                __reinsurance.CreatedOn           = DateTime.Now;
                                __reinsurance.CreatedBy           = customer.Id;

                                InsuranceContext.ReinsuranceTransactions.Insert(__reinsurance);

                                //SummeryofReinsurance += "<tr><td>" + Convert.ToString(__reinsurance.Id) + "</td><td>" + ReinsuranceCase.TreatyCode + "</td><td>" + ReinsuranceCase.TreatyName + "</td><td>" + Convert.ToString(__reinsurance.ReinsuranceAmount) + "</td><td>" + Convert.ToString(ReinsuranceBroker.ReinsuranceBrokerName) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(__reinsurance.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(ReinsuranceBroker.Commission) + "</td></tr>";

                                listReinsuranceTransaction.Add(__reinsurance);
                            }
                            else
                            {
                                var reinsurance = new ReinsuranceTransaction();
                                reinsurance.ReinsuranceAmount  = _item.SumInsured - ownRetention;
                                AutoFacSumInsured              = Convert.ToDecimal(reinsurance.ReinsuranceAmount);
                                reinsurance.ReinsurancePremium = Math.Round(Convert.ToDecimal((reinsurance.ReinsuranceAmount / item.SumInsured) * basicPremium), 2);
                                AutoFacPremium = Convert.ToDecimal(reinsurance.ReinsurancePremium);
                                reinsurance.ReinsuranceCommissionPercentage = Convert.ToDecimal(ReinsuranceBroker.Commission);
                                reinsurance.ReinsuranceCommission           = Math.Round(Convert.ToDecimal((reinsurance.ReinsurancePremium * reinsurance.ReinsuranceCommissionPercentage) / 100), 2);
                                reinsurance.VehicleId           = item.Id;
                                reinsurance.ReinsuranceBrokerId = ReinsuranceBroker.Id;
                                reinsurance.TreatyName          = ReinsuranceCase.TreatyName;
                                reinsurance.TreatyCode          = ReinsuranceCase.TreatyCode;
                                reinsurance.CreatedOn           = DateTime.Now;
                                reinsurance.CreatedBy           = customer.Id;

                                InsuranceContext.ReinsuranceTransactions.Insert(reinsurance);

                                //SummeryofReinsurance += "<tr><td>" + Convert.ToString(reinsurance.Id) + "</td><td>" + ReinsuranceCase.TreatyCode + "</td><td>" + ReinsuranceCase.TreatyName + "</td><td>" + Convert.ToString(reinsurance.ReinsuranceAmount) + "</td><td>" + Convert.ToString(ReinsuranceBroker.ReinsuranceBrokerName) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(reinsurance.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(ReinsuranceBroker.Commission) + "</td></tr>";

                                listReinsuranceTransaction.Add(reinsurance);
                            }


                            Insurance.Service.VehicleService obj = new Insurance.Service.VehicleService();
                            VehicleModel vehiclemodel            = InsuranceContext.VehicleModels.Single(where : $"ModelCode='{item.ModelId}'");
                            VehicleMake  vehiclemake             = InsuranceContext.VehicleMakes.Single(where : $" MakeCode='{item.MakeId}'");

                            string vehicledescription = vehiclemodel.ModelDescription + " / " + vehiclemake.MakeDescription;

                            // SummeryofVehicleInsured += "<tr><td>" + vehicledescription + "</td><td>" + Convert.ToString(item.SumInsured) + "</td><td>" + Convert.ToString(item.Premium) + "</td><td>" + AutoFacSumInsured.ToString() + "</td><td>" + AutoFacPremium.ToString() + "</td><td>" + FacSumInsured.ToString() + "</td><td>" + FacPremium.ToString() + "</td></tr>";

                            SummeryofVehicleInsured += "<tr><td style='padding:7px 10px; font-size:14px'><font size='2'>" + vehicledescription + "</font></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + Convert.ToString(item.SumInsured) + " </font></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + Convert.ToString(item.Premium) + "</font></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + AutoFacSumInsured.ToString() + "</font></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + AutoFacPremium.ToString() + "</ font ></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + FacSumInsured.ToString() + "</font></td><td style='padding:7px 10px; font-size:14px'><font size='2'>" + FacPremium.ToString() + "</font></td></tr>";
                        }
                    }
                }
            }

            // var summary = model.SummaryDetail;

            int?paymentMethod = model.SummaryDetail.PaymentMethodId;
            model.SummaryDetail = SetDataOnSummaryDetail(vehicle);
            model.SummaryDetail.InvoiceNumber   = policy.PolicyNumber;
            model.SummaryDetail.PaymentMethodId = paymentMethod;

            var DbEntry = Mapper.Map <SummaryDetailModel, SummaryDetail>(model.SummaryDetail);

            if (model.SummaryDetail != null)
            {
                DbEntry.CustomerId = customer.Id;
                bool _userLoggedin = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

                if (_userLoggedin)
                {
                    var _User         = UserManager.FindById(User.Identity.GetUserId().ToString());
                    var _customerData = InsuranceContext.Customers.All(where : $"UserId ='{_User.Id}'").FirstOrDefault();

                    if (_customerData != null)
                    {
                        DbEntry.CreatedBy = _customerData.Id;
                    }
                }


                DbEntry.CreatedOn = DateTime.Now;
                if (DbEntry.BalancePaidDate.Value.Year == 0001)
                {
                    DbEntry.BalancePaidDate = DateTime.Now;
                }
                if (DbEntry.Notes == null)
                {
                    DbEntry.Notes = "";
                }
                InsuranceContext.SummaryDetails.Insert(DbEntry);
            }



            if (DbEntry.Id > 0)
            {
                var SummaryDetails = InsuranceContext.SummaryVehicleDetails.All(where : $"SummaryDetailId={DbEntry.Id}").ToList();

                if (SummaryDetails != null && SummaryDetails.Count > 0)
                {
                    foreach (var item in SummaryDetails)
                    {
                        InsuranceContext.SummaryVehicleDetails.Delete(item);
                    }
                }


                var summarydetails = new SummaryVehicleDetail();
                summarydetails.SummaryDetailId  = DbEntry.Id;
                summarydetails.VehicleDetailsId = vehicleId;
                summarydetails.CreatedBy        = customer.Id;
                summarydetails.CreatedOn        = DateTime.Now;
                InsuranceContext.SummaryVehicleDetails.Insert(summarydetails);

                MiscellaneousService.UpdateBalanceForVehicles(DbEntry.AmountPaid.Value, DbEntry.Id, Convert.ToDecimal(DbEntry.TotalPremium), false);
            }

            if (listReinsuranceTransaction != null && listReinsuranceTransaction.Count > 0)
            {
                string filepath   = System.Configuration.ConfigurationManager.AppSettings["urlPath"];
                int    _vehicleId = 0;
                int    count      = 0;
                bool   MailSent   = false;
                foreach (var item in listReinsuranceTransaction)
                {
                    count++;
                    if (_vehicleId == 0)
                    {
                        SummeryofReinsurance = "<tr><td>" + Convert.ToString(item.Id) + "</td><td>" + item.TreatyCode + "</td><td>" + item.TreatyName + "</td><td>" + Convert.ToString(item.ReinsuranceAmount) + "</td><td>" + MiscellaneousService.GetReinsuranceBrokerNamebybrokerid(item.ReinsuranceBrokerId) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(item.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(item.ReinsuranceCommissionPercentage) + "%</td></tr>";
                        _vehicleId           = item.VehicleId;
                        MailSent             = false;
                    }
                    else
                    {
                        if (_vehicleId == item.VehicleId)
                        {
                            SummeryofReinsurance += "<tr><td>" + Convert.ToString(item.Id) + "</td><td>" + item.TreatyCode + "</td><td>" + item.TreatyName + "</td><td>" + Convert.ToString(item.ReinsuranceAmount) + "</td><td>" + MiscellaneousService.GetReinsuranceBrokerNamebybrokerid(item.ReinsuranceBrokerId) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(item.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(item.ReinsuranceCommissionPercentage) + "%</td></tr>";
                            var user = UserManager.FindById(customer.UserID);
                            Insurance.Service.EmailService objEmailService = new Insurance.Service.EmailService();
                            var    ePaymentTermData  = from ePaymentTerm e in Enum.GetValues(typeof(ePaymentTerm)) select new { ID = (int)e, Name = e.ToString() };
                            var    paymentTerm       = ePaymentTermData.FirstOrDefault(p => p.ID == model.SummaryDetail.PaymentTermId);
                            string SeheduleMotorPath = "/Views/Shared/EmaiTemplates/Reinsurance_Admin.cshtml";
                            string MotorBody         = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(SeheduleMotorPath));
                            var    Body = MotorBody.Replace("##PolicyNo##", policy.PolicyNumber).Replace("##path##", filepath).Replace("##Cellnumber##", user.PhoneNumber)
                                          .Replace("##FirstName##", customer.FirstName).Replace("##LastName##", customer.LastName)
                                          .Replace("##SummeryofVehicleInsured##", SummeryofVehicleInsured);

                            var attachementPath = MiscellaneousService.EmailPdf(Body, policy.CustomerId, policy.PolicyNumber, "Reinsurance Case");


                            List <string> attachements = new List <string>();
                            attachements.Add(attachementPath);

                            objEmailService.SendEmail(ZimnatEmail, "", "", "Reinsurance Case: " + policy.PolicyNumber.ToString(), Body, attachements);
                            MailSent = true;
                        }
                        else
                        {
                            SummeryofReinsurance = "<tr><td>" + Convert.ToString(item.Id) + "</td><td>" + item.TreatyCode + "</td><td>" + item.TreatyName + "</td><td>" + Convert.ToString(item.ReinsuranceAmount) + "</td><td>" + MiscellaneousService.GetReinsuranceBrokerNamebybrokerid(item.ReinsuranceBrokerId) + "</td><td>" + Convert.ToString(Math.Round(Convert.ToDecimal(item.ReinsurancePremium), 2)) + "</td><td>" + Convert.ToString(item.ReinsuranceCommissionPercentage) + "%</td></tr>";
                            MailSent             = false;
                        }
                        _vehicleId = item.VehicleId;
                    }


                    if (count == listReinsuranceTransaction.Count && !MailSent)
                    {
                        var user = UserManager.FindById(customer.UserID);
                        Insurance.Service.EmailService objEmailService = new Insurance.Service.EmailService();
                        var    ePaymentTermData  = from ePaymentTerm e in Enum.GetValues(typeof(ePaymentTerm)) select new { ID = (int)e, Name = e.ToString() };
                        var    paymentTerm       = ePaymentTermData.FirstOrDefault(p => p.ID == model.SummaryDetail.PaymentTermId);
                        string SeheduleMotorPath = "/Views/Shared/EmaiTemplates/Reinsurance_Admin.cshtml";
                        string MotorBody         = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(SeheduleMotorPath));
                        var    Body = MotorBody.Replace("##PolicyNo##", policy.PolicyNumber).Replace("##paath##", filepath).Replace("##Cellnumber##", user.PhoneNumber).Replace("##FirstName##", customer.FirstName).Replace("##LastName##", customer.LastName).Replace("##SummeryofVehicleInsured##", SummeryofVehicleInsured);

                        var attacehMentFilePath = MiscellaneousService.EmailPdf(Body, policy.CustomerId, policy.PolicyNumber, "Reinsurance Case");

                        List <string> _attachements = new List <string>();
                        _attachements.Add(attacehMentFilePath);
                        objEmailService.SendEmail(ZimnatEmail, "", "", "Reinsurance Case: " + policy.PolicyNumber.ToString(), Body, _attachements);
                        //MiscellaneousService.ScheduleMotorPdf(Body, policy.CustomerId, policy.PolicyNumber, "Reinsurance Case- " + policy.PolicyNumber.ToString(), item.VehicleId);
                    }
                }
            }


            if (model.SummaryDetail.PaymentMethodId == (int)InsuranceClaim.Models.paymentMethod.PayNow)
            {
                CustomerRegistrationController customerController = new CustomerRegistrationController();


                Insurance.Service.EmailService log = new Insurance.Service.EmailService();
                var payNow = customerController.PayNow(DbEntry.Id, policy.PolicyNumber, model.SummaryDetail.PaymentMethodId.Value, Convert.ToDecimal(model.SummaryDetail.TotalPremium));
                if (payNow.IsSuccessPayment)
                {
                    Session["PollUrl"] = payNow.PollUrl;

                    Session["PayNowSummmaryId"] = DbEntry.Id;


                    return(Redirect(payNow.ReturnUrl));
                }
                else
                {
                    return(RedirectToAction("failed_url", "Paypal"));
                }
            }
            else if (model.SummaryDetail.PaymentMethodId == (int)InsuranceClaim.Models.paymentMethod.ecocash)
            {
                return(RedirectToAction("EcoCashPayment", "Paypal", new { id = DbEntry.Id, invoiceNumber = policy.PolicyNumber, Paymentid = model.SummaryDetail.PaymentMethodId.Value }));
            }


            #endregion



            return(View());
        }
 public void DeleteSummaryVehicleDetails(SummaryVehicleDetail SummaryVehicleDetail)
 {
     InsuranceContext.SummaryVehicleDetails.Delete(SummaryVehicleDetail);
 }