예제 #1
0
        public async Task <DbResult> Send_Email_With_Attachement(string name, string email, string subject, string message, string file)
        {
            var result = new DbResult {
                Success = true
            };

            try
            {
                using (var mail = new MailMessage())
                {
                    mail.Body       = message;
                    mail.IsBodyHtml = true;
                    mail.Subject    = subject;
                    mail.Priority   = MailPriority.High;
                    mail.To.Add(new MailAddress(email, name));
                    mail.From = new MailAddress(_options.From, _options.Display_Name);
                    mail.Attachments.Add(new Attachment(file));
                    using (var client = GetSmtpClient())
                    {
                        await client.SendMailAsync(mail);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false; result.Message = ex.Message;
                string info = string.Format("SendEmailAsync: Name:- {0}, Email:- {1}, Subject:- {2}", name, email, subject);
                ExceptionGateway.AddException(new ExceptionLog(ex, info));
            }
            return(await Task.FromResult(result));
        }
예제 #2
0
        public void OnException(ExceptionContext context)
        {
            int statusCode = 500;
            var ex         = context.Exception;

            context.ExceptionHandled = true;
            string info = context.HttpContext.Request.Path.Value;

            Task.Run(async() => { await ExceptionGateway.AddExceptionAsync(new ExceptionLog(ex, info)); });
            context.HttpContext.Response.StatusCode = statusCode;
            context.HttpContext.Response.Redirect(string.Format("/error/{0}", statusCode));
        }
예제 #3
0
        public string GetMailTemplate(dynamic obj, string template)
        {
            string htmlBody = string.Empty;

            try
            {
                Email.DefaultRenderer = new RazorRenderer();
                var template_path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "email-template", template);
                var testEmail     = Email.From(_options.From).UsingTemplateFromFile(template_path, obj);
                htmlBody = testEmail.Data.Body;
            }
            catch (Exception ex)
            {
                string messgae = ex.Message;
                string info    = string.Format("GetMailTemplate: Template:- {0}", template);
                ExceptionGateway.AddException(new ExceptionLog(ex, info));
            }
            return(htmlBody);
        }
예제 #4
0
        public async Task <JsonResult> Create_Shipment_Order([FromBody] Shipment obj)
        {
            bool shipment_status = false;
            var  result          = new Models.DataProvider.DbResult();
            var  cart            = await _shop_repo.Shopping_Cart_Tracking_Get_By_Id(obj.Cart_Id);

            if (!cart.Status.Equals("Pending"))
            {
                result.Message = "Order already created."; return(Json(result));
            }

            var addr = await _addr_repo.Get_By_Id(cart.Shipping_Address_Id);

            cart.ShippingAddress = addr;
            string mobile = string.IsNullOrEmpty(addr.Mobile) ? string.Empty : addr.Mobile.StartsWith("+") ? addr.Mobile : string.Format("+{0}{1}", addr.ISDCode, addr.PhoneNumber);

            if (cart.CartType == "Shopping")
            {
                var dorship   = new Dorship(cart.Id, obj.PaymentType);
                var order_rec = new Receiver_Data(addr.Full_Name, mobile, cart.Email, addr.Country, addr.State, addr.City, addr.Address_Line, addr.ZipCode);
                order_rec.Street_Two  = addr.Address_Line2; order_rec.Street_Three = addr.Address_Line3;
                dorship.Receiver_Data = order_rec;

                var packages = new List <Package_Data>();

                foreach (var x in cart.ShopingCart)
                {
                    decimal price   = (obj.PaymentType == "cc") ? 0 : x.TotalPrice;
                    var     package = new Package_Data(x.SKU, price, x.Product_Name);
                    packages.Add(package);
                }
                dorship.Package_Data = packages;
                var shipment = await _fetchr.Create_Order_For_Shipment(dorship);

                if (shipment.Success)
                {
                    if (shipment.Data.Success)
                    {
                        result.Message = "Order created successfully.";
                        result.Success = shipment_status = true;
                        foreach (var x in shipment.Data.Dorship.Package_Data)
                        {
                            var abc = _shop_repo.Update_Shipment_Id(x.Tracking_No, shipment.Data.Dorship.Order_Reference, x.Package_Reference);
                            abc.Wait();
                        }
                        var ord = await _shop_repo.Shopping_Cart_Tracking_Update_Order_Status(obj.Cart_Id, shipment_status, obj.PaymentType, "Order Created");

                        var invoice_template = _emailSender.GetMailTemplate(cart, "invoice.cshtml");
                        var file             = Utility.Create_Invoice(invoice_template, cart.Id);
                        var invoice_path     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Resources", "Invoice", string.Format("{0}.pdf", cart.Id));
                        var html_template    = _emailSender.GetMailTemplate(cart, "order-confirmation.cshtml");
                        var mailResult       = await _emailSender.Send_Email_With_Attachement(cart.Name, cart.Email, "Order Confirmation", html_template, invoice_path);
                    }
                }
                else
                {
                    result.Message = shipment.Content;
                    await ExceptionGateway.AddExceptionAsync(new ExceptionLog(new Exception(string.Format("Error: Create_Order_For_Shipment, Id: {0}", obj.Cart_Id)), shipment.Content));
                }
            }

            if (cart.CartType == "Selling")
            {
                var pickup      = new PickUp();
                var pickup_data = new PickUp_Data {
                    Email = cart.Email, Phone_Number = mobile, Name = addr.Full_Name
                };
                pickup_data.Address         = string.Format("{0}, {1}", addr.Address_Line, addr.Area);
                pickup_data.City            = addr.City;
                pickup_data.Country         = addr.Country;
                pickup_data.Order_Reference = cart.Id;
                foreach (var item in cart.SellingCart)
                {
                    pickup_data.Product_Items.Add(new PickUp_Product {
                        Product_Description = string.Format("{0}, {1} ({2})", item.Product_Name, item.Product_TypeName, item.Product_Type)
                    });
                }
                pickup.Data.Add(pickup_data);

                var shipment = await _fetchr.Create_PickUp_Order(pickup);

                if (shipment.Success)
                {
                    if (shipment.Data.Success)
                    {
                        var resp = shipment.Data;
                        result.Message = "Order created successfully.";
                        result.Success = shipment_status = resp.Success;
                        if (shipment_status)
                        {
                            var abc = _shop_repo.Update_Shipment_Id_Pickup(resp.Tracking_Id, resp.Order_Reference);
                            abc.Wait();
                            var payment = await _pay_repo.Get();

                            await _credit_repo.Add_New(new Credit { Amount = cart.Total_Sum *payment.Credit_Ratio, IsBlocked = true, Trancaction_Id = obj.Cart_Id, Transaction_Type = "CREDIT", Transaction_For = "Selling", UserId = cart.UserId, Comments = string.Format("Added Credit for Order #{0}", obj.Cart_Id) });

                            var ord = await _shop_repo.Shopping_Cart_Tracking_Update_Order_Status(obj.Cart_Id, shipment_status, obj.PaymentType, "Order Created");

                            var invoice_template = _emailSender.GetMailTemplate(cart, "invoice.cshtml");
                            var file             = Utility.Create_Invoice(invoice_template, cart.Id);
                            var invoice_path     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Resources", "Invoice", string.Format("{0}.pdf", cart.Id));
                            var html_template    = _emailSender.GetMailTemplate(cart, "order-confirmation.cshtml");
                            var mailResult       = await _emailSender.Send_Email_With_Attachement(cart.Name, cart.Email, "Order Confirmation", html_template, invoice_path);
                        }
                    }
                }
                else
                {
                    result.Message = shipment.Content;
                    await ExceptionGateway.AddExceptionAsync(new ExceptionLog(new Exception(string.Format("Error: Create_Order_For_Shipment, Id: {0}", obj.Cart_Id)), shipment.Content));
                }
            }
            return(Json(result));
        }