当前位置: 首页>>代码示例>>C#>>正文


C# Cart.ComputeTotalValue方法代码示例

本文整理汇总了C#中SportsStore.Domain.Entities.Cart.ComputeTotalValue方法的典型用法代码示例。如果您正苦于以下问题:C# Cart.ComputeTotalValue方法的具体用法?C# Cart.ComputeTotalValue怎么用?C# Cart.ComputeTotalValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SportsStore.Domain.Entities.Cart的用法示例。


在下文中一共展示了Cart.ComputeTotalValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessorOrder

        public void ProcessorOrder(Cart cart, ShippingDetails shipping)
        {
            using(var smtpClient = new SmtpClient(emailSettings.Servername, emailSettings.Serverport))
            {
                smtpClient.EnableSsl = emailSettings.UseSsl;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);

                if(emailSettings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
                    smtpClient.EnableSsl = false;
                }

                StringBuilder body = new StringBuilder();
                body.AppendLine("A new order has been submitted");
                body.AppendLine("---");
                body.AppendLine("Items: ");

                foreach (var item in cart.Lines)
                {
                    var subtotal = item.Product.Price*item.Quantity;
                    body.AppendFormat("{0} x {1} (subtotal: {2})", item.Quantity, item.Product.Price, subtotal.ToString("c"));
                }

                body.AppendFormat("Total order value: {0}", cart.ComputeTotalValue().ToString("c"))
                    .AppendLine("---")
                    .AppendLine("Ship to: ")
                    .AppendLine(shipping.Name)
                    .AppendLine(shipping.Line1)
                    .AppendLine(shipping.Line2 ?? "")
                    .AppendLine(shipping.Line3 ?? "")
                    .AppendLine(shipping.City)
                    .AppendLine(shipping.State ?? "")
                    .AppendLine(shipping.Country)
                    .AppendLine(shipping.Zip)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}",  shipping.GiftWrap ? "Yes" : "No")
                    ;

                MailMessage mailMessage = new MailMessage(emailSettings.MailFromAddress, emailSettings.MailToAddress, "New order submitted!", body.ToString());

                if(emailSettings.WriteAsFile)
                {
                    mailMessage.BodyEncoding = Encoding.ASCII;
                }

                try
                {
                    smtpClient.Send(mailMessage);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine("Couldn't send mail: " + exception.Message);

                }

            }
        }
开发者ID:Gluba,项目名称:SportsStore,代码行数:60,代码来源:EmailOrderProcessor.cs

示例2: ProcessOrder

        public void ProcessOrder(Cart cart, ShippingDetails shippingInfo) {

            using (var smtpClient = new SmtpClient()) {

                smtpClient.EnableSsl = emailSettings.UseSsl;
                smtpClient.Host = emailSettings.ServerName;
                smtpClient.Port = emailSettings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials
                    = new NetworkCredential(emailSettings.Username,
                          emailSettings.Password);

                if (emailSettings.WriteAsFile) {
                    smtpClient.DeliveryMethod
                        = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
                    smtpClient.EnableSsl = false;
                }

                StringBuilder body = new StringBuilder()
                    .AppendLine("A new order has been submitted")
                    .AppendLine("---")
                    .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())
                    .AppendLine("---")
                    .AppendLine("Ship to:")
                    .AppendLine(shippingInfo.Name)
                    .AppendLine(shippingInfo.Line1)
                    .AppendLine(shippingInfo.Line2 ?? "")
                    .AppendLine(shippingInfo.Line3 ?? "")
                    .AppendLine(shippingInfo.City)
                    .AppendLine(shippingInfo.State ?? "")
                    .AppendLine(shippingInfo.Country)
                    .AppendLine(shippingInfo.Zip)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}",
                        shippingInfo.GiftWrap ? "Yes" : "No");

                MailMessage mailMessage = new MailMessage(
                                       emailSettings.MailFromAddress,   // From
                                       emailSettings.MailToAddress,     // To
                                       "New order submitted!",          // Subject
                                       body.ToString());                // Body

                if (emailSettings.WriteAsFile) {
                    mailMessage.BodyEncoding = Encoding.ASCII;
                }

                //smtpClient.Send(mailMessage);
               
            }
        }
开发者ID:rogerertas,项目名称:SportsStore,代码行数:60,代码来源:EmailOrderProcessor.cs

示例3: BuildMailMessage

 private MailMessage BuildMailMessage(Cart cart, ShippingDetails shippingDetails)
 {
     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(shippingDetails.Name);
     body.AppendLine(shippingDetails.Line1);
     body.AppendLine(shippingDetails.Line2 ?? "");
     body.AppendLine(shippingDetails.Line3 ?? "");
     body.AppendLine(shippingDetails.City);
     body.AppendLine(shippingDetails.State ?? "");
     body.AppendLine(shippingDetails.Country);
     body.AppendLine(shippingDetails.Zip);
     body.AppendLine("---");
     body.AppendFormat("Gift wrap: {0}", shippingDetails.GiftWrap ? "Yes" : "No");
     return new MailMessage("[email protected]", // From
                            mailTo,                    // To
                            "New order submitted!",    // Subject
                            body.ToString());          // Body
 }
开发者ID:sbetchel,项目名称:SportsStore,代码行数:30,代码来源:EmailOrderSubmitter.cs

示例4: List

        public ViewResult List(Cart cart, string category, int page = 1)
        {
            var products = _productRepository.Products
                                             .Where(p => category == null || p.Category == category)
                                             .OrderBy(p => p.ProductID)
                                             .Skip((page - 1)*PageSize)
                                             .Take(PageSize);

            string carttotal = cart.ComputeTotalValue().ToString("c");
            int quantity = cart.Lines.Sum(x => x.Quantity);

            ProductListViewModel viewModel = new ProductListViewModel
                                                 {
                                                     Products = products,
                                                     PagingInfo = new PagingInfo
                                                                      {
                                                                          CurrentPage = page,
                                                                          ItemsPerPage = PageSize,
                                                                          TotalItems = category == null
                                                                            ? _productRepository.Products.Count()
                                                                            : _productRepository.Products.Count(x => x.Category == category)
                                                                      },
                                                     CurrentCategory = category,
                                                     CartTotal = carttotal,
                                                     CartQuantity = quantity
                                                 };

            return View(viewModel);
        }
开发者ID:tenzinkabsang,项目名称:SportsStoreKnockoutified,代码行数:29,代码来源:ProductController.cs

示例5: CombineMessage

        private string CombineMessage(Cart cart, ShippingDetails shippingDetails)
        {
            StringBuilder body = new StringBuilder()
                    .AppendLine("A new order has been submitted")
                    .AppendLine("---")
                    .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())
                .AppendLine("---")
                .AppendLine("Ship to:")
                .AppendLine(shippingDetails.Name)
                .AppendLine(shippingDetails.Line1)
                .AppendLine(shippingDetails.Line2 ?? "")
                .AppendLine(shippingDetails.Line3 ?? "")
                .AppendLine(shippingDetails.City)
                .AppendLine(shippingDetails.State ?? "")
                .AppendLine(shippingDetails.Country)
                .AppendLine(shippingDetails.Zip)
                .AppendLine("---")
                .AppendFormat("Gift wrap: {0}", shippingDetails.GiftWrap ? "Yes" : "No");

            return body.ToString();
        }
开发者ID:brainiacOnly,项目名称:SportsStore,代码行数:29,代码来源:InternetEmailOrderProcessor.cs

示例6: ProcessOrder

        public void ProcessOrder(Cart cart, ShippingDetails shippingInfo)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = emailSettings.UseSsl;
                smtpClient.Host = emailSettings.ServerName;
                smtpClient.Port = emailSettings.ServerPort;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new NetworkCredential(emailSettings.UserName, emailSettings.Password);
                smtpClient.Timeout = 10000;

                if (emailSettings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
                    smtpClient.EnableSsl = false;
                }

                StringBuilder body = new StringBuilder()
                    .AppendLine("Nowe zamówienie")
                    .AppendLine("---")
                    .AppendLine("Produkty:");

                foreach (var line in cart.Lines)
                {
                    var subtotal = line.Product.Price*line.Quantity;
                    body.AppendFormat("{0} x {1} (wartość: {2:c})", line.Quantity, line.Product.Name, subtotal);
                }

                body.AppendFormat("Wartosc calkowita:{0:c}", cart.ComputeTotalValue())
                    .AppendLine("---")
                    .AppendLine("Wysylka dla:")
                    .AppendLine(shippingInfo.Name)
                    .AppendLine(shippingInfo.Line1)
                    .AppendLine(shippingInfo.Line2 ?? "")
                    .AppendLine(shippingInfo.Line3 ?? "")
                    .AppendLine(shippingInfo.City)
                    .AppendLine(shippingInfo.State ?? "")
                    .AppendLine(shippingInfo.Country)
                    .AppendLine(shippingInfo.Zip)
                    .AppendLine("---")
                    .AppendFormat("Pakowanie prezentu: {0}", shippingInfo.GiftWrap ? "Tak" : "Nie");

                MailMessage mailMessage = new MailMessage(
                    emailSettings.MailFromAddress,
                    emailSettings.MailToAddress,
                    "Otrzymano nowe zamówienie!",
                    body.ToString());
                mailMessage.Priority = MailPriority.High;

                if (emailSettings.WriteAsFile)
                {
                    mailMessage.BodyEncoding = Encoding.ASCII;
                }

                smtpClient.Send(mailMessage);
            }
        }
开发者ID:SHassona,项目名称:Personal-Repository,代码行数:59,代码来源:EmailOrderProcessor.cs

示例7: ProcessOrder

        public void ProcessOrder(Cart cart, ShippingDetails shippingDetails)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = emailSettings.UseSsl;
                smtpClient.Host = emailSettings.ServerName;
                smtpClient.Port = emailSettings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);

                if (emailSettings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
                    smtpClient.EnableSsl = false;
                }

                StringBuilder body = new StringBuilder()
                    .AppendLine("A new order has being submitted")
                    .AppendLine("---")
                    .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())
                    .AppendLine("---")
                    .AppendLine("Ship to")
                    .AppendLine(shippingDetails.Name)
                    .AppendLine(shippingDetails.Line1)
                    .AppendLine(shippingDetails.Line2 ?? "")
                    .AppendLine(shippingDetails.Line3 ?? "")
                    .AppendLine(shippingDetails.City)
                    .AppendLine(shippingDetails.Zip ?? "")
                    .AppendLine(shippingDetails.Country)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}", shippingDetails.GiftWrap ? "Yes" : "No");

                MailMessage message = new MailMessage();
                AlternateView plainView = AlternateView.CreateAlternateViewFromString(body.ToString(), null, MediaTypeNames.Text.Plain);
                message.From = new MailAddress(emailSettings.MailFromAddress);
                message.To.Add(emailSettings.MailToAddress);
                message.Subject = "New order submitted";
                message.AlternateViews.Add(plainView);

                if (emailSettings.WriteAsFile)
                {
                    message.BodyEncoding = Encoding.ASCII;
                }

                smtpClient.Send(message);
            }
        }
开发者ID:djandreski,项目名称:SportsStore,代码行数:56,代码来源:EmailOrderProcessor.cs

示例8: Calculate_Car_Total

        public void Calculate_Car_Total()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1", Price=10 };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price=5};

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 3);

            Assert.AreEqual(target.ComputeTotalValue(), 25);
        }
开发者ID:pasena,项目名称:SportsStore,代码行数:12,代码来源:CartTest.cs

示例9: Calculate_Card_Total

        public void Calculate_Card_Total()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1",Price=100 };
            Product p2 = new Product { ProductID = 2, Name = "P2",Price=150 };

            Cart target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            decimal res= target.ComputeTotalValue();

            Assert.AreEqual(res, 250);
        }
开发者ID:SergioKritskiy,项目名称:SportStore,代码行数:12,代码来源:CartTest.cs

示例10: AjaxAdd

        public ActionResult AjaxAdd(Cart cart, int productId)
        {
            Product product = _productRepository.Products.FirstOrDefault(p => p.ProductID == productId);

            if (product != null)
                cart.AddItem(product, 1);

            int cartQuantity = cart.Lines.Sum(x => x.Quantity);
            string cartTotal = cart.ComputeTotalValue().ToString("c");

            return Json(new { success = true, cartQuantity, cartTotal });
        }
开发者ID:tenzinkabsang,项目名称:SportsStoreKnockoutified,代码行数:12,代码来源:CartController.cs

示例11: CalculateCartTotal

        public void CalculateCartTotal()
        {
            Product p1 = new Product() { Id = 1, Name = "P1", Price = 100M};
            Product p2 = new Product() { Id = 2, Name = "P2", Price = 50M};
            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            decimal result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
开发者ID:MichalZawadzki,项目名称:SportsStore,代码行数:13,代码来源:CartTests.cs

示例12: Calculate_Cart_Total

 public void Calculate_Cart_Total()
 {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
     Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Act
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     target.AddItem(p1, 3);
     decimal result = target.ComputeTotalValue(); // Assert
     Assert.AreEqual(result, 450M);
 }
开发者ID:jorgepkim,项目名称:SportsStore,代码行数:14,代码来源:CartTests.cs

示例13: Calculate_Cart_Total

        public void Calculate_Cart_Total()
        {
            var p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            var p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            decimal result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
开发者ID:Meleagre,项目名称:SportsStore,代码行数:14,代码来源:CartTests.cs

示例14: Calculate_Cart_Total

        public void Calculate_Cart_Total()
        {
            Product p1 = new Product() { ProductID = 1, Name = "P1", Price = 25M };
            Product p2 = new Product() { ProductID = 2, Name = "P2", Price = 20M };
            Product p3 = new Product() { ProductID = 3, Name = "P3", Price = 5M };
            Cart cart = new Cart();
            cart.AddItem(p1, 2);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            cart.AddItem(p1, 6);

            decimal result = cart.ComputeTotalValue();

            Assert.AreEqual(result, 245);
        }
开发者ID:pavlove,项目名称:SportsStore,代码行数:15,代码来源:CartTests.cs

示例15: Compute_TotalValue_Of_Cart

        public void Compute_TotalValue_Of_Cart()
        {
            //Arrange
            Cart target = new Cart(); // TODO: Initialize to an appropriate value

            target.AddItem(products[0], 5);
            target.AddItem(products[1], 2);
            target.AddItem(products[2], 3);

            //Act
            decimal total = target.ComputeTotalValue();

            //Assert
            Assert.AreEqual(total, 139M);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:15,代码来源:CartTest.cs


注:本文中的SportsStore.Domain.Entities.Cart.ComputeTotalValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。