EPiServerSiteCMS.Business.OrdersBL.GetAllOrdersDetails C# (CSharp) Méthode

GetAllOrdersDetails() public méthode

public GetAllOrdersDetails ( string cookieUserName ) : List
cookieUserName string
Résultat List
        public List<JsonOrderItem> GetAllOrdersDetails(string cookieUserName)
        {
            PurchaseOrder[] orders = null;

            List<JsonOrderItem> list = new List<JsonOrderItem>();
            if (SecurityContext.Current.CurrentUserId != null)
            {

                orders = OrderContext.Current.GetPurchaseOrders(SecurityContext.Current.CurrentUserId).ToArray();
                //Collect for every order item the important details.
                foreach (var orderItem in orders)
                {
                    var ownerName = orderItem.CustomerName;
                    var tranckingNumber = orderItem.TrackingNumber;
                    var expData = orderItem.ExpirationDate;
                    var currency = orderItem.BillingCurrency;
                    var totalAmmountSum = orderItem.ShippingTotal;
                    var totalAmmountItems = orderItem.HandlingTotal;

                    //Create a wrapper object with the details collected before.
                    JsonOrderItem jsonOrderItemsList = new JsonOrderItem();

                    jsonOrderItemsList.ownerName = orderItem.CustomerName;
                    jsonOrderItemsList.tranckingNumber = tranckingNumber;
                    jsonOrderItemsList.expData = expData.ToString();
                    jsonOrderItemsList.totalAmmountItems = totalAmmountItems.ToString("F");

                    // Remove the float decimals from the number of items in the cart by returning a substring.
                    int lengthOfTotalItems = jsonOrderItemsList.totalAmmountItems.Length;
                    jsonOrderItemsList.totalAmmountItems = jsonOrderItemsList.totalAmmountItems.Substring(0,
                        lengthOfTotalItems - 2);

                    jsonOrderItemsList.totalAmmountSum = totalAmmountSum.ToString("F");
                    jsonOrderItemsList.currency = currency;

                    //Add new order details to list.
                    list.Add(jsonOrderItemsList);
                }
            }

            //Set the owner name for the current order as founded email value.
            var listLength = list.Count -1;
            list[listLength].ownerName = cookieUserName;
            return list;
        }

Usage Example

Exemple #1
0
        /*
         The method sends all orders stored in the database to the test email.
         * It uses security context in order to take the current logged user.
         */
        public void SendMail()
        {
            //Create a new smtp client. Set the credentials for the host user.
            SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential("*****@*****.**", "testTechromX123");

            // Call the business login in order to take all the order details for the current user.
            OrdersBL ordersBl = new OrdersBL();
            List<JsonOrderItem> orderItemList = ordersBl.GetAllOrdersDetails( SecurityContext.Current.CurrentUserName);

            // Create the string that will be the body of the sended mail by iterating every order element from the taken list.
            String bodyString = null;
            foreach (var itemOrder in orderItemList)
            {
                String lineString = null;
                lineString = "Owner Name: " + itemOrder.ownerName.ToString() + "\n" + "Expiration Data: " + itemOrder.expData.ToString() + "\n" +
                    "Tracking Number: " + itemOrder.tranckingNumber.ToString() + "\n" + "Total Number Of Items: " + itemOrder.totalAmmountItems.ToString() +"\n"+
                    "Total Sum " + itemOrder.totalAmmountSum.ToString() + itemOrder.currency.ToString() + "\n";
                bodyString += "\n" + lineString;
            }

            //Sends the mail to the implicit writed test account.
            MailMessage mm = new MailMessage("*****@*****.**", "*****@*****.**", "YourEpiServerOrder", bodyString);
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            client.Send(mm);
        }
All Usage Examples Of EPiServerSiteCMS.Business.OrdersBL::GetAllOrdersDetails