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


C# Cart.ComputeTotalCost方法代码示例

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


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

示例1: ProcessOrder

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

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

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

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

                body.AppendFormat("Total order value {0:c}", cart.ComputeTotalCost())
                    .AppendLine("---")
                    .AppendLine("Ship to:")
                    .AppendLine(shippingDetails.Name)
                    .AppendLine(shippingDetails.Line1)
                    .AppendLine(shippingDetails.Line2 ?? string.Empty)
                    .AppendLine(shippingDetails.Line3 ?? string.Empty)
                    .AppendLine(shippingDetails.City)
                    .AppendLine(shippingDetails.State ?? string.Empty)
                    .AppendLine(shippingDetails.Country)
                    .AppendLine(shippingDetails.Zip ?? string.Empty)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}", shippingDetails.Wrap ? "yes" : "no");

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

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

                smtp.Send(mailMessage);
            }
        }
开发者ID:gabla5,项目名称:LearningProjects,代码行数:51,代码来源:OrderProcessor.cs


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