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


C# Cart.CoputeTotalValue方法代码示例

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


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

示例1: 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;
                }
                var 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.CoputeTotalValue())
                    .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");  
                var 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:Itdotaer,项目名称:SportsStore,代码行数:49,代码来源:OrderProcessor.cs

示例2: CalculateCartTotal

        public void CalculateCartTotal()
        {
            //arrange
            var prod1 = new Product { ProductID = 1, Name = "p1", Price = 100M};
            var prod2 = new Product { ProductID = 2, Name = "p2", Price = 50M};

            //arrange
            var target = new Cart();

            //act
            target.AddProduct(prod1, 2);
            target.AddProduct(prod1, 8);
            target.AddProduct(prod2, 1);
            var result = target.CoputeTotalValue();

            //assert
            Assert.AreEqual(1050M, result);
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:18,代码来源:Products.cs


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