public ActionResult Payment()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    decimal total  = 0;
                    int     result = 0;

                    if (Session[CommonConstants.USER_SESSION] == null)
                    {
                        return(Redirect("/dang-nhap"));
                    }
                    var userLogin = Session[CommonConstants.USER_SESSION] as UserLogin;
                    var user      = UserBLL.GetUserByID(userLogin.UserName);
                    var order     = new Order
                    {
                        ShipName    = user.Name,
                        ShipMobile  = user.Phone,
                        ShipAddress = user.Address,
                        ShipEmail   = user.Email
                    };
                    OrderBLL.InsertOrder(order);
                    var cart = Session[CommonConstants.CART_SESSION] as List <CartItem>;
                    for (int i = 0; i < cart.Count; i++)
                    {
                        var orderDetails = new OrderDetail
                        {
                            ProductID = cart[i].ProductID,
                            OrderID   = order.ID,
                            Quantity  = cart[i].Quantity,
                            Price     = cart[i].Price
                        };
                        result = OrderDetailsBLL.InsertOrderDetails(orderDetails);
                        total += (cart[i].Price * cart[i].Quantity);
                    }
                    if (result > 0)
                    {
                        Session[CommonConstants.USER_SESSION] = null;
                        //string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/NewOrder.html"));
                        //content = content.Replace("{{CustomerName}}", user.Name);
                        //content = content.Replace("{{Phone}}", user.Phone);
                        //content = content.Replace("{{Email}}", user.Email);
                        //content = content.Replace("{{Address}}", user.Address);
                        //content = content.Replace("{{Total}}", total.ToString("N0"));
                        //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                        //var mailHelper = new MailHelper();
                        //mailHelper.SendEmail(user.Email, "Đơn hàng mới từ OnlineShop", content);
                        //mailHelper.SendEmail(toEmail, "Đơn hàng mới từ OnlineShop", content);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                return(Redirect("/hoan-thanh"));
            }
            ViewBag.Cart = Cart();

            return(View());
        }
Exemplo n.º 2
0
 // POST: api/OrderDetails
 public bool Post([FromBody] ORDERDETAILS details) => OrderDetailsBLL.InsertOrderDetails(details);