public ActionResult CreateOrder() { // load cart trong session. var shoppingCart = LoadShoppingCart(); if (shoppingCart.GetCartItems().Count <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad request")); } // chuyển thông tin shopping cart thành Order. var contract = new Contract { TotalPrice = shoppingCart.GetTotalPrice(), CustomerId = 1, MotorInsurances = new List <MotorInsurance>() }; foreach (var cartItem in shoppingCart.GetCartItems()) { var motorinsurance = new MotorInsurance() { InsurancePackageId = cartItem.Value.InsurancePackageId, RegisteredAddress = cartItem.Value.RegisteredAddress, CarOwner = cartItem.Value.CarOwner, ChassisNumber = cartItem.Value.ChassisNumber, LicensePlate = cartItem.Value.LicensePlate, Duration = cartItem.Value.Duration, ContractId = contract.Id, Quantity = cartItem.Value.Quantity, UnitPrice = cartItem.Value.Price }; contract.MotorInsurances.Add(motorinsurance); db.Contracts.Add(contract); } db.SaveChanges(); ClearCart(); // lưu vào database. var transaction = db.Database.BeginTransaction(); try { transaction.Commit(); } catch (Exception e) { Console.WriteLine(e); transaction.Rollback(); } return(Redirect("/MotorCart/ShowCart")); }
/// <summary> /// Get the schedule for specific insurance type (Motor or Home or Travel or Domestic) /// </summary> /// <param name="request">Schedule request.</param> /// <returns>Schedule file path.</returns> public DownloadScheduleResponse GetScheduleFilePath(DownloadScheuleRequest request) { try { string FilePath = string.Empty; if (request.InsuranceType == Constants.Insurance.Travel) { TravelInsurance travel = new TravelInsurance(); TravelSavedQuotationResponse travelresult = travel.GetSavedQuotationByPolicy(request.DocNo, "portal", request.AgentCode, request.IsEndorsement, request.EndorsementID); FilePath = this.CreateTravelSchudles(travelresult, false); } else if (request.InsuranceType == Constants.Insurance.Motor) { MotorInsurance motor = new MotorInsurance(); MotorSavedQuotationResponse motorresult = motor.GetSavedMotorPolicy(request.DocNo, "", request.AgentCode, request.IsEndorsement, request.EndorsementID, request.RenewalCount); FilePath = this.CreateMotorSchudles(motorresult.MotorPolicyDetails, false); } else if (request.InsuranceType == Constants.Insurance.DomesticHelp) { DomesticHelp domestic = new DomesticHelp(); DomesticHelpSavedQuotationResponse domesticresult = domestic.GetSavedDomesticPolicy(request.DocNo, request.AgentCode, request.IsEndorsement, request.EndorsementID); FilePath = this.CreateDomesticSchudles(domesticresult, false); } else { HomeInsurance home = new HomeInsurance(); HomeSavedQuotationResponse homeresult = home.GetSavedQuotationPolicy(request.DocNo, "", request.AgentCode, request.IsEndorsement, request.EndorsementID, request.RenewalCount); FilePath = CreateHomeSchudles(homeresult, false); } return(new DownloadScheduleResponse { FilePath = FilePath, IsTransactionDone = true }); } catch (Exception ex) { return(new DownloadScheduleResponse { IsTransactionDone = false, TransactionErrorMessage = ex.Message }); } }
/// <summary> /// Get motor proposal file. /// </summary> /// <param name="request">Schedule request.</param> /// <returns>Schedule file path.</returns> public DownloadScheduleResponse GetProposalFilePath(DownloadScheuleRequest request) { try { string FilePath = string.Empty; if (request.InsuranceType == Constants.Insurance.Motor) { MotorInsurance motor = new MotorInsurance(); MotorSavedQuotationResponse motorresult = motor.GetSavedMotorPolicy(request.DocNo, "", request.AgentCode, false, 0, request.RenewalCount); FilePath = this.CreateMotorProposal(motorresult.MotorPolicyDetails, false); } return(new DownloadScheduleResponse { FilePath = FilePath, IsTransactionDone = true }); } catch (Exception ex) { return(new DownloadScheduleResponse { IsTransactionDone = false, TransactionErrorMessage = ex.Message }); } }
public ActionResult CreateContract() { var shoppingCart = LoadShoppingCart(); if (shoppingCart.GetCartItems().Count <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad request")); } var contract = new Contract { TotalPrice = shoppingCart.GetTotalPrice(), UserID = User.Identity.GetUserId(), InsuranceId = 3, MotorInsurances = new List <MotorInsurance>() }; var mt = db.MotorInsurances.ToList(); foreach (var cartItem in shoppingCart.GetCartItems()) { var motorInsurance = new MotorInsurance() { InsurancePackageId = cartItem.Value.InsurancePackageId, RegisteredAddress = cartItem.Value.RegisteredAddress, CarOwner = cartItem.Value.CarOwner, ChassisNumber = cartItem.Value.ChassisNumber, LicensePlate = cartItem.Value.LicensePlate, Duration = cartItem.Value.Duration, ContractId = contract.Id, Quantity = cartItem.Value.Quantity, UnitPrice = cartItem.Value.Price }; contract.MotorInsurances.Add(motorInsurance); db.Contracts.Add(contract); } db.SaveChanges(); // lưu vào database. var transaction = db.Database.BeginTransaction(); try { var em = db.Users.Where(x => x.Id == contract.UserID).FirstOrDefault(); var senderemail = new MailAddress("*****@*****.**", "Insurance Company"); var receivermail = new MailAddress(em.Email, "Insurance Company"); var passwordemail = "vtacl123"; var subject = "Notification Order"; string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">" + "<style>table, td, th {border: 1px solid black; font-size: 15px}</style>" + "<style> p {font-size: 18px}</style>" ; body += "<p>" + "Your order information." + "</p>" + "<p>" + "Name Insurance : MotorInsurance</p>" + "<p>" + "Total Price :" + contract.TotalPrice + "$" + "</p>" + "<br>"; body += "</HEAD><BODY>" + "<tr>" + "<th>Package Insurance</th>" + "<th>RegisteredAddress</th>" + "<th>CarOwner</th>" + "<th>ChassisNumber</th>" + "<th>LicensePlate</th>" + "<th>Duration</th>" + "<th>Quantity</th>" + "<th>UnitPrice</th>" + "</tr>"; foreach (var item in shoppingCart.GetCartItems()) { body += "<tr>" + "<td>" + item.Value.InsurancePackageName + "</td>" + "<td>" + item.Value.RegisteredAddress + "</td>" + "<td>" + item.Value.CarOwner + "</td>" + "<td>" + item.Value.ChassisNumber + "</td>" + "<td>" + item.Value.LicensePlate + "</td>" + "<td>" + item.Value.Duration + "</td>" + "<td>" + item.Value.Quantity + "</td>" + "<td>" + item.Value.Price + "</td>" + "</tr>"; } var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, DeliveryMethod = SmtpDeliveryMethod.Network, EnableSsl = true, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderemail.Address, passwordemail) }; using (var mess = new MailMessage(senderemail, receivermail) { IsBodyHtml = true, Subject = subject, Body = body } ) { smtp.Send(mess); }; ClearCart(); transaction.Commit(); } catch (Exception e) { Console.WriteLine(e); transaction.Rollback(); } return(Redirect("/OrderNotice/Index")); }