Ejemplo n.º 1
0
        public static void SendOrderConfirmation(tbl_Orders order)
        {
            if (order != null && !string.IsNullOrEmpty(order.CustomerEMail))
            {
                var templateData = new Dictionary<string, object>();
                templateData.Add("ORDERDATE", order.O_Timestamp.GetValueOrDefault());
                templateData.Add("DELIVERYDATE", order.O_DeliveryDate ?? String.Empty);
                templateData.Add("DOMAIN", order.tbl_Domains.DO_Domain);
                templateData.Add("ORDERID", order.OrderID);
                templateData.Add("INSTRUCTION", order.O_DeliveryNotes ?? String.Empty);
                templateData.Add("ISDISCOUNT", order.O_DiscountID.GetValueOrDefault(0) != 0);
                templateData.Add("ISDONATION", order.DependentOrders.Any());
                templateData.Add("DISCOUNTAMOUNT", order.GetDiscountAmountString());
                templateData.Add("DELIVERYAMOUNT", order.GetDeliveryAmountString());
                templateData.Add("TOTALAMOUNT", order.GetPriceString());
                templateData.Add("TOTALAMOUNTPAID", order.TotalAmountToPay.ToString("C"));

                templateData.Add("BADDRESS1", order.BillingAddress1 ?? String.Empty);
                templateData.Add("BADDRESS2", order.BillingAddress2 ?? String.Empty);
                templateData.Add("BADDRESS3", order.BillingAddress3 ?? String.Empty);
                templateData.Add("BNAME", order.BillingFirstnames + " " + order.BillingSurname);
                templateData.Add("BTOWN", order.BillingCity ?? String.Empty);
                templateData.Add("BCOUNTY", order.BillingState ?? String.Empty);
                templateData.Add("BPOSTCODE", order.BillingPostCode ?? String.Empty);
                templateData.Add("BCOUNTRY", order.BillingCountry ?? String.Empty);
                templateData.Add("BPHONE", order.BillingPhone ?? String.Empty);

                templateData.Add("DADDRESS1", order.DeliveryAddress1 ?? String.Empty);
                templateData.Add("DADDRESS2", order.DeliveryAddress2 ?? String.Empty);
                templateData.Add("DADDRESS3", order.DeliveryAddress3 ?? String.Empty);
                templateData.Add("DNAME", order.DeliveryFirstnames + " " + order.DeliverySurname);
                templateData.Add("DTOWN", order.DeliveryCity ?? String.Empty);
                templateData.Add("DCOUNTY", order.DeliveryState ?? String.Empty);
                templateData.Add("DPOSTCODE", order.DeliveryPostCode ?? String.Empty);
                templateData.Add("DCOUNTRY", order.DeliveryCountry ?? String.Empty);
                templateData.Add("DPHONE", order.DeliveryPhone ?? String.Empty);

                var products = order.tbl_OrderContent.Select(oc => new
                {
                    Name = oc.OC_Title ?? String.Empty,
                    Price = oc.GetItemPriceString(),
                    Quantity = oc.OC_Quantity.GetValueOrDefault(0),
                    TotalPrice = oc.GetPriceString()
                }).ToList();

                if (order.DependentOrders.Any())
                {
                    products.AddRange(order.DependentOrders.Select(o => new
                    {
                        Name = "Donation",
                        Price = o.TotalAmount.ToString(),
                        Quantity = (short)1,
                        TotalPrice = o.TotalAmount.ToString()
                    }));
                }
                templateData.Add("PRODUCTS", products);

                // switch between donations, products and events templates
                string template = order.O_ProductTypeID.HasValue && order.tbl_ProductTypes.PT_Name == ProductType.Donation.ToString() ?
                    GetTemplate(EmailVariables.DonationConfirmation, templateData) :
                    GetTemplate(EmailVariables.OrderConfirmation, templateData);

                // change email title accordingly
                string title = order.O_ProductTypeID.HasValue && order.tbl_ProductTypes.PT_Name == ProductType.Donation.ToString() ? "Donation Confirmation" : "Order Confirmation";

                var recipients = new List<string>() { order.CustomerEMail };
                MailSender.Instance.SendEmail(recipients, null, null, title, template);
            }
        }