Exemple #1
0
        public ActionResult Create([Bind(Include = "OrderDetailID,OrderID,ProductID,ProductName,ProductCode,UnitPrice,Quantity,PromotionPrice,CreateDate,CreateUser,ModifiedDate,ModifiedUser,IsActive")] OrderDetail orderDetail)
        {
            var UserSession = (UserLogin)Session[TechDeviShopVs002.Common.CommonConstants.USER_SESSION];

            if (ModelState.IsValid)
            {
                var _dal = new OrderDetailsDAL();

                orderDetail.CreateUser = UserSession.UserID;
                var pd = new ProductDAL().ViewDetail(orderDetail.ProductID);
                orderDetail.ProductName    = pd.ProductName;
                orderDetail.ProductCode    = pd.ProductCode;
                orderDetail.UnitPrice      = pd.Price;
                orderDetail.PromotionPrice = pd.PromotionPrice;

                int id = _dal.Insert(orderDetail);
                if (id > 0)
                {
                    return(RedirectToAction("Index", "OrderDetails"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm Chi tiết hóa đơn ko thành công");
                }
            }
            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", orderDetail.ProductID);
            //ViewBag.ProductName = new SelectList(db.Products, "ProductName", "ProductName", orderDetail.ProductName);
            //ViewBag.ProductCode = new SelectList(db.Products, "ProductCode", "ProductCode", orderDetail.ProductCode);
            //ViewBag.UnitPrice = new SelectList(db.Products, "UnitPrice", "Price", orderDetail.UnitPrice);
            //ViewBag.PromotionPrice = new SelectList(db.Products, "PromotionPrice", "PromotionPrice", orderDetail.PromotionPrice);
            return(View(orderDetail));
        }
Exemple #2
0
        public ViewResult ODofOrder(int oID)
        {
            var model = new OrderDetailsDAL().ListByOrderID(oID);

            ViewBag.ODinfo = new OrderDAL().ViewDetail(oID);
            return(View(model));
        }
        public ActionResult CompleteOrder(int id)
        {
            var order = new OrderDAL().ViewDetail(id);

            order.OrderStatusID = 4;

            var _dal = new OrderDAL();

            var listOD = new OrderDetailsDAL().ListByOrderID(id).ToList();

            foreach (var item in listOD)
            {
                //Edit Product Quantity
                var product = new ProductDAL().ViewDetail(item.ProductID);
                if (product.Quantity > 1)
                {
                    product.Quantity = product.Quantity - (int)item.Quantity;
                }
                var productResult = new ProductDAL().Update(product);
            }

            var _result = _dal.Update(order);

            if (_result)
            {
                return(RedirectToAction("Index", "Orders"));
            }
            else
            {
                ModelState.AddModelError("", "Cập nhật trạng thái không thành công ko thành công");
            }

            return(View(order));
        }
        public ActionResult HistoryOrderDetail(int id)
        {
            ViewBag.HOrderDetail = new OrderDAL().ViewDetail(id);

            var listSCD = new OrderDetailsDAL().ListByOrderID(id).ToList();

            return(View(listSCD));
        }
        public ActionResult Checkout(FormCollection f)
        {
            User_Account  userAccount = (User_Account)Session["USER"];
            DateTime      today       = DateTime.Today;
            string        email       = userAccount.Email;
            string        name        = f["txtName"];
            string        address     = f["txtAddress"];
            string        province    = f["province"];
            string        district    = f["district"];
            string        town        = f["town"];
            string        orderPhone  = f["txtNumber"];
            Order_Details order       = new Order_Details
            {
                Email           = email,
                Ordered_Date    = today,
                Delivered       = false,
                Cancelled_Order = false,
                Reason_Cancel   = "",
                Order_Name      = name,
                Exact_Address   = address,
                Order_Phone     = orderPhone,
                Province_ID     = Int32.Parse(province),
                District_ID     = Int32.Parse(district),
                Town_ID         = Int32.Parse(town)
            };
            OrderDetailsDAL dal            = new OrderDetailsDAL();
            int             orderDetailsId = dal.addOrder(order);

            if (orderDetailsId >= 0)
            {
                ICollection <Product_Cart> productCarts   = userAccount.Product_Cart;
                Product_CartDAL            productCartDal = new Product_CartDAL();
                foreach (var item in productCarts)
                {
                    ProductOrderDetailsDAL podDal = new ProductOrderDetailsDAL();
                    Product_Order_Details  pod    = new Product_Order_Details()
                    {
                        Product_ID       = item.Product_ID,
                        Order_ID         = orderDetailsId,
                        Order_Quantity   = (int)item.Quantity,
                        Price            = item.Product.Price,
                        Discount_Percent = item.Product.DiscountPercent,
                    };

                    podDal.addProductOrderDetails(pod);

                    productCartDal.deleteRecord(item.Product_ID, userAccount.Email);
                }
                productCarts.Clear();
                Session.Remove("CART");
                return(RedirectToAction("Index", "Congratulate"));
            }

            return(View());
        }
Exemple #6
0
        // GET: Admin/OrderDetails/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var orderDetail = new OrderDetailsDAL().ViewDetail(id);

            if (orderDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(orderDetail));
        }
Exemple #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["AID"] == null)
     {
         Response.Redirect("Default.aspx");
     }
     if (!IsPostBack)
     {
         string OID = Request.QueryString["OID"];
         this.Repeater1.DataSource = OrdersDAL.getOrdersByOID(OID);
         this.Repeater1.DataBind();
         this.Repeater2.DataSource = OrderDetailsDAL.getOrderDetailByOID(OID);
         this.Repeater2.DataBind();
     }
 }
        public ActionResult OrderCancel(int id)
        {
            var CusUserSession = (CusUserLogin)Session[TechDeviShopVs002.Common.CommonConstants.CusUserSession];

            var cust = new CustomerDAL().ViewDetail(CusUserSession.CustomerID);

            var order = new OrderDAL().ViewDetail(id);

            try
            {
                var listOrderDetail = new OrderDetailsDAL().ListByOrderID(id);

                decimal total = 0;
                foreach (var item in listOrderDetail)
                {
                    //calculated total price;
                    total += (item.Product.PromotionPrice.GetValueOrDefault(0) * (decimal)item.Quantity);
                }

                order.OrderStatusID = 5;
                order.ModifiedDate  = DateTime.Now;
                var _result = new OrderDAL().Update(order);

                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", order.CusName);
                content = content.Replace("{{Phone}}", order.CusPhone);
                content = content.Replace("{{Email}}", order.CusEmail);
                content = content.Replace("{{Address}}", order.Address);
                content = content.Replace("{{OrderID}}", order.OrderID.ToString());
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(order.CusEmail, "Đơn hàng bị hủy bỏ từ OnlineShop", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng bị hủy bỏ từ OnlineShop", content);
            }
            catch (Exception)
            {
                //ghi log
                return(Redirect("/loi-huy-bo"));
            }
            return(Redirect("/huy-bo-thanh-cong"));
        }
Exemple #9
0
        // GET: Admin/OrderDetails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var orderDetail = new OrderDetailsDAL().ViewDetail(id);

            if (orderDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", orderDetail.ProductID);
            //ViewBag.ProductName = new SelectList(db.Products, "ProductName", "ProductName", orderDetail.ProductName);
            //ViewBag.ProductCode = new SelectList(db.Products, "ProductCode", "ProductCode", orderDetail.ProductCode);
            //ViewBag.UnitPrice = new SelectList(db.Products, "UnitPrice", "Price", orderDetail.UnitPrice);
            //ViewBag.PromotionPrice = new SelectList(db.Products, "PromotionPrice", "PromotionPrice", orderDetail.PromotionPrice);
            return(View(orderDetail));
        }
Exemple #10
0
 public static int addOrderDetails(OrderDetails o)
 {
     return(OrderDetailsDAL.addOrderDetails(o));
 }
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var CusUserSession = (CusUserLogin)Session[TechDeviShopVs002.Common.CommonConstants.CusUserSession];
            var _sc            = new ShoppingCartDAL().FindByCus(CusUserSession.CustomerID);

            var order = new Order();

            order.CustomerID       = CusUserSession.CustomerID;
            order.OrderDate        = DateTime.Now;
            order.Address          = address;
            order.CusPhone         = mobile;
            order.CusName          = shipName;
            order.CusEmail         = email;
            order.ShipperID        = 1;
            order.ShippingMethodID = 2;
            order.OrderStatusID    = 1;
            order.IsActive         = true;

            try
            {
                var id = new OrderDAL().Insert(order);
                //var cart = (List<CartItem>)Session[CartSession];

                int scid    = _sc.ShoppingCartID;
                var listSCD = new ShoppingCartDetailDAL().ListByShoppingCartID(scid).ToList();

                decimal total = 0;
                foreach (var item in listSCD)
                {
                    //Create order detail;
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID      = item.Product.ProductID;
                    orderDetail.OrderID        = id;
                    orderDetail.ProductName    = item.Product.ProductName;
                    orderDetail.ProductCode    = item.Product.ProductCode;
                    orderDetail.UnitPrice      = item.Product.Price;
                    orderDetail.PromotionPrice = item.Product.PromotionPrice;
                    orderDetail.Quantity       = item.Quantity;
                    orderDetail.IsActive       = true;
                    var detailDal = new OrderDetailsDAL().Insert(orderDetail);


                    //End Shopping Cart
                    var spcart = new ShoppingCartDAL().ViewDetail(item.ShoppingCartID);
                    spcart.ExpireDate = DateTime.Now;
                    var spcartResult = new ShoppingCartDAL().Update(spcart);

                    //calculated total price;
                    total += (item.Product.Price.GetValueOrDefault(0) * (int)item.Quantity);
                }


                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch (Exception)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
Exemple #12
0
 public OrderDetailsBO()
 {
     OrderDetailsDAL = new OrderDetailsDAL();
 }