public void SubmitOrder(Cart cart) { StringBuilder body = new StringBuilder(); body.AppendLine("A new order has been submitted"); body.AppendLine("---"); body.AppendLine("Items:"); foreach(var line in cart.Lines) { var subtotal = line.Product.Price * line.Quantity; body.AppendFormat("{0} x {1} (subtotal: {2:c})", line.Quantity, line.Product.Name, subtotal); } body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue()); body.AppendLine("---"); body.AppendLine("Ship to:"); body.AppendLine(cart.ShippingDetails.Name); body.AppendLine(cart.ShippingDetails.Line1); body.AppendLine(cart.ShippingDetails.Line2 ?? ""); body.AppendLine(cart.ShippingDetails.Line3 ?? ""); body.AppendLine(cart.ShippingDetails.City); body.AppendLine(cart.ShippingDetails.State ?? ""); body.AppendLine(cart.ShippingDetails.Country); body.AppendLine(cart.ShippingDetails.Zip); body.AppendLine("---"); body.AppendFormat("Gift wrap: {0}", cart.ShippingDetails.GiftWrap ? "Yes" : "No"); SmtpClient smtpClient = new SmtpClient(smtpServer); smtpClient.Send(new MailMessage(mailFrom, mailTo, MailSubject, body.ToString())); }
public void SubmitOrder(Cart cart) { StringBuilder body = new StringBuilder(); body.AppendLine("Bạn đã đăng kí đơn đặt hàng này:"); body.AppendLine("----------------------------------"); body.AppendLine("Danh sách xe được mua:"); foreach (var line in cart.Lines) { var subtotal = line.Product.Price * line.Quantity; body.AppendFormat(" {0} x {1} (Thành tiền: {2:c})" + Environment.NewLine, line.Quantity,line.Product.Name,subtotal); } body.AppendLine("----------------------------------"); body.AppendFormat("Tổng tiền thanh toán: {0:c}" + Environment.NewLine, cart.ComputeTotalValue()); body.AppendLine("--------***---------"); body.AppendLine("Hàng hóa được chuyển đến:"); body.AppendLine(cart.ShippingDetails.Name); body.AppendLine(cart.ShippingDetails.BirthOfDay.ToShortDateString()); body.AppendLine(cart.ShippingDetails.Career ?? ""); body.AppendLine(cart.ShippingDetails.Address ?? ""); body.AppendLine(cart.ShippingDetails.City); body.AppendLine(cart.ShippingDetails.State ?? ""); body.AppendLine(cart.ShippingDetails.Country); body.AppendLine(cart.ShippingDetails.Zip); body.AppendLine("---------***---------"); body.AppendFormat("Nhận quà: {0}"+Environment.NewLine,cart.ShippingDetails.GiftWrap ? "Có" : "Không"); body.AppendLine("---------***---------"); body.AppendLine("Cám ơn bạn đã tin tưởng đặt mua hàng tại website chúng tôi!"); body.AppendLine("Trân trọng kính chào quý khách."); SmtpClient smtpClient = new SmtpClient(); smtpClient.Credentials = new NetworkCredential(mailFrom, pass); smtpClient.Port = int.Parse(serverport); smtpClient.Host = smtpServer; smtpClient.EnableSsl = true; smtpClient.Send(new MailMessage(mailFrom, cart.ShippingDetails.Email , MailSubject,body.ToString())); }
public void Calculates_Total_Value_Correctly() { Cart cart = new Cart(); cart.AddItem(new Product { ProductID = 1, Price = 5 }, 10); cart.AddItem(new Product { ProductID = 2, Price = 2.1M }, 3); cart.AddItem(new Product { ProductID = 3, Price = 1000 }, 1); Assert.AreEqual(1056.3, cart.ComputeTotalValue()); }
public void Cart_Starts_Empty() { Cart cart = new Cart(); Assert.AreEqual(0, cart.Lines.Count); Assert.AreEqual(0, cart.ComputeTotalValue()); }
public void Summary_Action_Renders_View_With_Total() { CartController controller = new CartController(null, null); Cart cart = new Cart(); Product p1 = new Product() { ProductID = 1, Price = 12 }; Product p2 = new Product() { ProductID = 2, Price = 50 }; cart.AddItem(p1, 12); cart.AddItem(p2, 5); ViewResult result = controller.Summary(cart); Assert.AreEqual(cart, ((Cart)result.ViewData.Model)); Assert.AreEqual(cart.Lines.Count, ((Cart)result.ViewData.Model).Lines.Count); Assert.AreEqual(cart.ComputeTotalValue(), ((Cart)result.ViewData.Model).ComputeTotalValue()); }