示例#1
0
 async public Task <IActionResult> AddMail(Mail mail)
 {
     try
     {
         var user   = httpContext.User.Identity as ClaimsIdentity;
         var userId = user.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value;
         var mgr    = new MailManager();
         return(Ok(await mgr.AddMail(mail)));
     }
     catch (Exception ex)
     {
         _logger.LogError($"GetChannelChats: {ex.Message}");
     }
     return(StatusCode(500, "Error adding mail"));
 }
示例#2
0
    private void SendMail(BusinessEntities.Orders order)
    {
        StringBuilder sb = new StringBuilder();

        sb = sb.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "NewOrder.html"));

        sb.Replace("{URL}", BaseSiteUrl);
        sb.Replace("{ORDERNUMBER}", order.OrderID.ToString());
        sb.Replace("{ORDERDATE}", GetStoreTime().ToString("MM/dd/yyyy HH:mm"));
        sb.Replace("{FULLNAME}", txtFirstName.Text + " " + txtLastName.Text);
        sb.Replace("{ADDRESS}", txtAddress.Text);
        sb.Replace("{CITY}", txtCity.Text);
        sb.Replace("{STATE}", txtState.Text);
        sb.Replace("{ZIPCODE}", txtZipCode.Text);
        sb.Replace("{PHONE}", txtTelephone.Text);
        if (!String.IsNullOrEmpty(txtMobile.Text))
        {
            sb.Replace("{MOBILE}", !String.IsNullOrEmpty(txtTelephone.Text) ? " - " + txtMobile.Text : txtMobile.Text);
        }
        else
        {
            sb.Replace("{MOBILE}", "");
        }
        if (order.OrderTypeID == BusinessEntities.OrderType.Deliver)
        {
            sb.Replace("{ORDERDELIVERY}", "Pizzaness Delivery");
        }
        else
        {
            sb.Replace("{ORDERDELIVERY}", "Self Pickup");
        }

        if (order.PaymentMethod == BusinessEntities.PaymentType.OnlinePayment)
        {
            sb.Replace("{PAYMENTMETHOD}", "Online Payment");
        }
        else
        {
            sb.Replace("{PAYMENTMETHOD}", "Cash Payment");
        }
        StringBuilder finalTemplate = new StringBuilder();

        for (int i = 0; i < order.OrderDetailsList.Count; i++)
        {
            BusinessEntities.OrderDetails orderDetails = order.OrderDetailsList.ElementAt(i);
            StringBuilder newTemplate = new StringBuilder();
            newTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "OrderDetailTemplate.html"));
            newTemplate.Replace("{ITEMQUANTITY}", orderDetails.Quantity.ToString());
            newTemplate.Replace("{PRODUCTNAME}", orderDetails.ProductName);
            newTemplate.Replace("{PRODUCTTYPE}", !String.IsNullOrEmpty(orderDetails.CategoryName) ? orderDetails.CategoryName : "");
            newTemplate.Replace("{PRICE}", orderDetails.Price.ToString());
            newTemplate.Replace("{RECIPENTNAME}", orderDetails.RecipientName);
            newTemplate.Replace("{INSTRUCTION}", orderDetails.Comments);

            StringBuilder optionTemplate = new StringBuilder();

            foreach (BusinessEntities.OrderDetailOptions obj in SessionOrderDetailOptionList.ElementAt(i))
            {
                //optionTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "OptionTemplate.html"));
                //optionTemplate.Replace("{OPTIONSTYPE}", obj.ProductOptionTypeName);
                optionTemplate.Append(obj.ProductOptionName + ",");
            }

            StringBuilder toppings = new StringBuilder();
            String        previousAddonTypeName = String.Empty;
            StringBuilder toppingTemplate       = new StringBuilder();
            if (orderDetails.IsGroupProduct)
            {
                List <BusinessEntities.OrderDetailSubProduct> subProducts = orderDetails.OrderDetailSubProducts;
                StringBuilder finalSubProductTemplate = new StringBuilder();
                foreach (BusinessEntities.OrderDetailSubProduct subProduct in subProducts)
                {
                    StringBuilder subProductTemplate = new StringBuilder();
                    subProductTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "SubProductTemplate.html"));
                    subProductTemplate.Replace("{PRODUCTNAME}", subProduct.ProductName);
                    subProductTemplate.Replace("{RECIPENTNAME}", subProduct.RecipientName);
                    subProductTemplate.Replace("{INSTRUCTION}", subProduct.Comments);

                    StringBuilder subProductOptionTemplate = new StringBuilder();

                    if (subProduct.OrderDetailSubProductOptions != null)
                    {
                        foreach (BusinessEntities.OrderDetailSubProductOption subProductOption in subProduct.OrderDetailSubProductOptions)
                        {
                            //subProductOptionTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "OptionTemplate.html"));
                            //subProductOptionTemplate.Replace("{OPTIONSTYPE}", subProductOption.ProductOptionTypeName);
                            subProductOptionTemplate.Append(subProductOption.ProductOptionName + ",");
                        }
                    }
                    toppings = new StringBuilder();
                    previousAddonTypeName = String.Empty;
                    toppingTemplate       = new StringBuilder();
                    foreach (BusinessEntities.OrderDetailSubProductAdon obj in subProduct.OrderDetailSubProductAdons)
                    {
                        if (obj.SelectedAdonOption != 0)
                        {
                            if (!obj.AdonTypeName.Equals(previousAddonTypeName))
                            {
                                toppings.Append(" <b>" + obj.AdonTypeName + ":</b>");
                                previousAddonTypeName = obj.AdonTypeName;
                            }
                            toppings.Append(Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->",
                                                                 "<!-- End Topping-->", false));
                            if (obj.IsDoubleSelected)
                            {
                                toppings.Replace("{DOUBLE}", "Two times ");
                            }
                            else
                            {
                                toppings.Replace("{DOUBLE}", "");
                            }
                            toppings.Replace("{NAME}", obj.AdonName);
                            toppings.Replace("{OPTION}",
                                             ((BusinessEntities.SelectedOption)obj.SelectedAdonOption).ToString());
                        }
                    }

                    if (!String.IsNullOrEmpty(toppings.ToString()))
                    {
                        String subString = Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->", "<!-- End Topping-->", true);
                        toppingTemplate.Replace(subString, toppings.ToString());
                    }
                    subProductTemplate.Replace("<!-- Options -->", subProductOptionTemplate.ToString().TrimEnd(new char[] { ',' }));
                    subProductTemplate.Replace("<!-- Topping -->", toppingTemplate.ToString());
                    finalSubProductTemplate.Append(subProductTemplate.ToString());
                }
                newTemplate.Replace("<!--SubProducts-->", finalSubProductTemplate.ToString());
                toppings        = new StringBuilder();
                toppingTemplate = new StringBuilder();
            }
            foreach (BusinessEntities.OrderDetailAdOns obj in SessionOrderAdonList.ElementAt(i))
            {
                if (obj.SelectedAdonOption != 0)
                {
                    if (!obj.AdonTypeName.Equals(previousAddonTypeName))
                    {
                        toppings.Append(" <b>" + obj.AdonTypeName + ":</b>");
                        previousAddonTypeName = obj.AdonTypeName;
                    }


                    toppings.Append(obj.AdonName);
                    if (obj.SelectedAdonOption == SelectedOption.FirstHalf)
                    {
                        if (obj.IsDoubleSelected)
                        {
                            toppings.Append("(Left 2 Times),");
                        }
                        else
                        {
                            toppings.Append("(Left),");
                        }
                    }
                    else if (obj.SelectedAdonOption == SelectedOption.SecondHalf)
                    {
                        if (obj.IsDoubleSelected)
                        {
                            toppings.Append("(Right 2 Times),");
                        }
                        else
                        {
                            toppings.Append("(Right),");
                        }
                    }
                    else
                    {
                        toppings.Append(",");
                    }
                }
            }
            if (!String.IsNullOrEmpty(toppings.ToString()))
            {
                //String subString = Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->", "<!-- End Topping-->", true);
                toppingTemplate.Append(toppings.ToString());
            }
            newTemplate.Replace("<!--OrderDetailOptions-->", optionTemplate.ToString().TrimEnd(new char[] { ',' }));
            newTemplate.Replace("<!--OrderDetailToppings-->", toppingTemplate.ToString().TrimEnd(new char[] { ',' }));
            finalTemplate.Append(newTemplate.ToString());
            //finalTemplate.Append(optionTemplate.ToString());
            //finalTemplate.Append(toppingTemplate.ToString());
        }
        String DetailTemplate = Utility.GetSubString(sb.ToString(), "<!--DETAIL TEMPLATE-->", "<!--END DETAIL TEMPLATE-->", true);

        DetailTemplate = DetailTemplate.Replace("<!--DETAILTEMPLATE-->", finalTemplate.ToString());

        sb.Replace(Utility.GetSubString(sb.ToString(), "<!--DETAIL TEMPLATE-->", "<!--END DETAIL TEMPLATE-->", true), DetailTemplate.ToString());
        sb.Replace("{TIP}", order.LineTip.ToString("C2"));
        sb.Replace("{TOTALPRICE}", order.OrderTotal.ToString("C2"));
        try
        {
            var mail = new Mail();
            mail.Subject       = "New Order";
            mail.Sender        = ConfigurationManager.AppSettings["DonotReplyEmail"];
            mail.Receiver      = SessionUser.Username;
            mail.MailCc        = string.Empty;
            mail.MailBcc       = ConfigurationManager.AppSettings["OrderReceiveEmail"];
            mail.MailBody      = sb.ToString();
            mail.IsHtml        = true;
            mail.ReferenceId   = order.OrderID;
            mail.ReferenceType = "Order";
            mailManager.AddMail(mail);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }