コード例 #1
0
 public ActionResult Cart()
 {
     try
     {
         if (Session["BeEdited"] != null)
         {
             MvcApplication.changeStatusNotifer.Dispose();
             string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId=", (int)Session["UserId"]);
             MvcApplication.changeStatusNotifer.Start("BMAChangeDB", dependencyCheckSql);
             MvcApplication.changeStatusNotifer.Change += this.OnChange3;
         }
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         int quantity = 0;
         if (Session["Cart"] == null || Session["UserRole"] != null)
         {
             return RedirectToAction("Index", "Product");
         }
         ViewBag.taxRate = cob.GetTaxRate();
         List<CustomerCartViewModel> lstCart = GetCart();
         if (lstCart.Count == 0)
         {
             return RedirectToAction("Index", "Product");
         }
         List<DiscountByQuantity> dbq = db.DiscountByQuantities.ToList();
         Policy policy = db.Policies.SingleOrDefault(n => n.PolicyId == 1);
         ViewBag.policy = policy;
         foreach (var item in lstCart)
         {
             quantity += item.Quantity;
         }
         if (dbq[0].beUsing)
         {
             TempData["Discount"] = cob.checkDiscount(quantity);
             return View(lstCart);
         }
         else
         {
             return View(lstCart);
         }
     }
     catch
     {
         return RedirectToAction("Index", "Error");
     }
 }
コード例 #2
0
        //public int GetDateAndNote(string planDeliveryDate, string Note)
        //{
        //    try
        //    {
        //        Session["DeliveryDate"] = planDeliveryDate;
        //        Session["Note"] = Note;
        //        return 1;
        //    }
        //    catch
        //    {
        //        return -1;
        //    }
        //}
        public ActionResult ProceedCheckout(FormCollection f)
        {
            try
            {
                CustomerOrderBusiness cob = new CustomerOrderBusiness();
                int quantity = 0;
                if (Session["Cart"] == null)
                {
                    return RedirectToAction("Index", "Home");
                }
                ViewBag.taxRate = cob.GetTaxRate();
                string planDeliveryDate = f["txtDelivery"].ToString();
                Session["DeliveryDate"] = planDeliveryDate;
                string Note = f["txtNote"];
                Session["Note"] = Note;
                List<CustomerCartViewModel> lstCart = GetCart();
                foreach (var item in lstCart)
                {
                    if (!cob.IsActiveProduct(item.ProductId))
                    {
                        ViewBag.productName = item.ProductName;
                    }
                }
                if (lstCart.Count == 0)
                {
                    return RedirectToAction("Index", "Product");
                }
                List<Boolean> dbq = db.DiscountByQuantities.Select(n => n.beUsing).ToList();
                foreach (var item in lstCart)
                {
                    quantity += item.Quantity;
                }
                if (dbq[0])
                {
                    TempData["Discount"] = cob.checkDiscount(quantity);
                }
                else
                {

                }
                return View(lstCart);
            }
            catch
            {
                return RedirectToAction("Index", "Error");
            }
        }
コード例 #3
0
 //For customer order
 public int OrderProduct()
 {
     try
     {
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         if (Session["Cart"] == null)
         {
             return -1;
         }
         List<CustomerCartViewModel> cart = GetCart();
         string orderTime = DateTime.Now.ToString("yyyyMMdd");
         //DateTime planDeliveryDate = DateTime.Now;
         DateTime planDeliveryDate = DateTime.ParseExact(Session["DeliveryDate"].ToString(), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
         string Note = Session["Note"].ToString();
         int amount = Convert.ToInt32(Session["Amount"]);
         int taxAmount = Convert.ToInt32(Session["TaxAmount"]);
         int discount = Convert.ToInt32(Session["DiscountAmount"]);
         int cusUserId = Convert.ToInt32(Session["UserId"]);
         if (Session["User"] != null)
         {
             TempData["userName"] = (Session["User"] as User).Username;
             TempData["phoneNumber"] = Session["Phonenumber"].ToString();
         }
         else
         {
             return -1;
         }
         foreach (var item in cart)
         {
             if (!cob.IsActiveProduct(item.ProductId))
             {
                 return -2;
             }
         }
         cob.OrderProduct(orderTime, planDeliveryDate, amount, taxAmount, discount, cusUserId, cart, Note);
         TempData["orderCode"] = cob.GetOrderCode();
         Session["Cart"] = null;
         Session["Amount"] = null;
         Session["TaxAmount"] = null;
         Session["DiscountAmount"] = null;
         Session["Note"] = null;
         return 1;
     }
     catch
     {
         return -3;
     }
 }
コード例 #4
0
 public ActionResult OrderSuccess()
 {
     try
     {
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         var lstOrderItems = cob.OrderSuccess();
         return View(lstOrderItems);
     }
     catch
     {
         return RedirectToAction("Index", "Error");
     }
 }
コード例 #5
0
        public int GuestOrderProduct(FormCollection f)
        {
            try
            {
                CustomerOrderBusiness cob = new CustomerOrderBusiness();
                if (Session["Cart"] == null)
                {
                    return -1;
                }
                List<CustomerCartViewModel> cart = GetCart();
                string orderTime = DateTime.Now.ToString("yyyyMMdd");
                int amount = Convert.ToInt32(Session["Amount"]);
                int taxAmount = Convert.ToInt32(Session["TaxAmount"]);
                int discount = Convert.ToInt32(Session["DiscountAmount"]);
                DateTime planDeliveryDate = DateTime.ParseExact(Session["DeliveryDate"].ToString(), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
                string Note = Session["Note"].ToString();
                string sName = f.Get("txtName").ToString();
                string sPhone = f.Get("txtPhoneNumber").ToString();
                string sAddress = f.Get("txtAddress").ToString();
                string sEmail = f.Get("txtEmail").ToString();

                if (sName == null || sPhone == null || sAddress == null || sEmail == null)
                {
                    RedirectToAction("OrderInfo");
                }

                if (cob.checkStaffDuplicate(sEmail, sPhone))
                {
                    return -2;
                }
                //Kiểm tra guest đó có tồn tại trong dtb user hoặc guest chưa
                if (cob.checkCustomerDuplicate(sEmail, sPhone))
                {
                    return -3;
                }

                //if (cob.checkGuestDuplicate(sName, sPhone, sEmail))
                //{
                //    cob.GuestOrderProduct(orderTime, planDeliveryDate, amount, taxAmount, cart, sName, sPhone, sEmail);
                //}
                else
                {
                    cob.GuestOrderProduct(orderTime, planDeliveryDate, amount, taxAmount, discount, cart, sName, sPhone, sAddress, sEmail, Note);
                }
                TempData["orderCode"] = cob.GetOrderCode();
                Session["Cart"] = null;
                Session["Amount"] = null;
                Session["TaxAmount"] = null;
                Session["DiscountAmount"] = null;
                Session["Note"] = null;
                return 1;
            }
            catch
            {
                return -4;
            }
        }
コード例 #6
0
 //For customer after enter information
 public int LoginOrderProduct(FormCollection f)
 {
     try
     {
         AccountBusiness ab = new AccountBusiness();
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         if (Session["Cart"] == null)
         {
             return -4;
         }
         List<CustomerCartViewModel> cart = GetCart();
         string orderTime = DateTime.Now.ToString("yyyyMMdd");
         int amount = Convert.ToInt32(Session["Amount"]);
         int taxAmount = Convert.ToInt32(Session["TaxAmount"]);
         int discount = Convert.ToInt32(Session["DiscountAmount"]);
         string sAccount = f.Get("txtAccount").ToString();
         string sPassword = f.Get("txtPassword").ToString();
         User endUser = ab.checkLogin(sAccount, sPassword);
         if (endUser != null)
         {
             int checkRole = endUser.RoleId;
             if (checkRole != 3)
             {
                 TempData["Notify"] = "Tài khoản không hợp lệ";
                 return -2;
             }
             Session["User"] = endUser;
             Session["UserId"] = endUser.UserId;
             Session["CusUserId"] = endUser.Customers.ElementAt(0).CustomerId;
             TempData["userName"] = endUser.Username.ToString();
             Session["Phonenumber"] = endUser.Customers.ElementAt(0).CustomerPhoneNumber.ToString();
         }
         else
         {
             TempData["Notify"] = "Sai tài khoản hoặc mật khẩu";
             return -3;
         }
         int cusUserId = Convert.ToInt32(Session["UserId"]);
         DateTime planDeliveryDate = DateTime.ParseExact(Session["DeliveryDate"].ToString(), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
         string Note = Session["Note"].ToString();
         cob.OrderProduct(orderTime, planDeliveryDate, amount, taxAmount, discount, cusUserId, cart, Note);
         TempData["orderCode"] = cob.GetOrderCode();
         Session["Cart"] = null;
         Session["Amount"] = null;
         Session["TaxAmount"] = null;
         Session["DiscountAmount"] = null;
         Session["Note"] = null;
         return 1;
     }
     catch
     {
         return -5;
     }
 }
コード例 #7
0
 public ActionResult GetOrderToCart(int orderId)
 {
     try
     {
         MvcApplication.changeStatusNotifer.Dispose();
         CusManageBusiness cmb = new CusManageBusiness();
         var order = cmb.GetOrderDetail(orderId);
         if (order.CustomerUserId != Convert.ToInt32(Session["UserId"]))
         {
             return RedirectToAction("Index", "Home");
         }
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         cob.TurnFlagOn(orderId);
         List<CustomerCartViewModel> lstCart = new List<CustomerCartViewModel>();
         lstCart = cob.GetOrderToCart(orderId);
         if (lstCart != null)
         {
             Session["Cart"] = lstCart;
             Session["BeEdited"] = orderId;
             Session["DeliveryDate"] = order.PlanDeliveryTime;
             Session["Note"] = order.OrderNote;
         }
         return RedirectToAction("Cart");
     }
     catch (Exception)
     {
         return RedirectToAction("Index", "Error");
     }
 }
コード例 #8
0
 public int EditOrder(int orderId)
 {
     try
     {
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         if (Session["Cart"] == null)
         {
             return -1;
         }
         List<CustomerCartViewModel> cart = GetCart();
         foreach (var item in cart)
         {
             if (!cob.IsActiveProduct(item.ProductId))
             {
                 return -2;
             }
         }
         //DateTime planDeliveryDate = Convert.ToDateTime(f.Get("txtDeliveryDate"));
         DateTime planDeliveryDate = DateTime.ParseExact(Session["DeliveryDate"].ToString(), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
         string Note = Session["Note"].ToString();
         int amount = Convert.ToInt32(Session["Amount"]);
         int taxAmount = Convert.ToInt32(Session["TaxAmount"]);
         int discount = Convert.ToInt32(Session["DiscountAmount"]);
         int cusUserId = Convert.ToInt32(Session["UserId"]);
         if (Session["User"] != null)
         {
             TempData["userName"] = (Session["User"] as User).Username;
             TempData["phoneNumber"] = Session["Phonenumber"].ToString();
         }
         else
         {
             RedirectToAction("Index", "Product");
         }
         bool checkEditError = cob.EditOrder(orderId, planDeliveryDate, amount, taxAmount, discount, cusUserId, cart, Note);
         if (!checkEditError)
         {
             Session["Cart"] = null;
             return -3;
         }
         cob.EditOrder(orderId, planDeliveryDate, amount, taxAmount, discount, cusUserId, cart, Note);
         cob.TurnFlagOff(orderId);
         TempData["orderCode"] = cob.EditGetOrderCode(orderId);
         Session["DeliveryDate"] = planDeliveryDate;
         Session["Cart"] = null;
         Session["BeEdited"] = null;
         Session["Amount"] = null;
         Session["TaxAmount"] = null;
         Session["DiscountAmount"] = null;
         Session["Note"] = null;
         return 1;
     }
     catch
     {
         return -4;
     }
 }
コード例 #9
0
 public int CheckProductActive()
 {
     try
     {
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         List<CustomerCartViewModel> lstCart = GetCart();
         foreach (var item in lstCart)
         {
             if (!cob.IsActiveProduct(item.ProductId))
             {
                 return -1;
             }
         }
         return 1;
     }
     catch
     {
         return -2;
     }
 }
コード例 #10
0
 public ActionResult OrderDetail(int orderId)
 {
     try
     {
         CusManageBusiness cmb = new CusManageBusiness();
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         int quantity = 0;
         var order = cmb.GetOrderDetail(orderId);
         if (order.CustomerUserId != Convert.ToInt32(Session["UserId"]))
         {
             return RedirectToAction("Index", "Home");
         }
         var orderItems = cmb.GetOrderItem(orderId);
         ViewBag.taxRate = cob.GetTaxRate();
         ViewBag.orderItems = orderItems;
         foreach (var item in orderItems)
         {
             quantity += item.Quantity;
         }
         ViewBag.Discount = cob.checkDiscount(quantity);
         return View(order);
     }
     catch (Exception)
     {
         return RedirectToAction("Index", "Error");
     }
 }
コード例 #11
0
 public ActionResult ConfirmOrder(int orderId)
 {
     try
     {
         CusManageBusiness cmb = new CusManageBusiness();
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         int quantityConfirm = 0;
         int quantityOld = 0;
         var orderCheck = cmb.GetOrderDetail(orderId);
         if (orderCheck.CustomerUserId != Convert.ToInt32(Session["UserId"]))
         {
             return RedirectToAction("Index", "Home");
         }
         Order confirmedOrder = cmb.GetOrderDetail(orderId);
         List<OrderItem> orderItems = cmb.GetOrderItem(orderId);
         int? previousId = confirmedOrder.PreviousOrderId;
         Order oldOrder = cmb.GetOrderDetail(previousId);
         List<OrderItem> oldOrderItems = cmb.GetOrderItem(previousId);
         foreach (var item in orderItems)
         {
             quantityConfirm += item.Quantity;
         }
         ViewBag.DiscountConfirm = cob.checkDiscount(quantityConfirm);
         foreach (var item in oldOrderItems)
         {
             quantityOld += item.Quantity;
         }
         ViewBag.DiscountOld = cob.checkDiscount(quantityOld);
         ViewBag.taxRate = cob.GetTaxRate();
         ViewBag.oldOrder = oldOrder;
         ViewBag.orderItems = orderItems;
         ViewBag.oldOrderItems = oldOrderItems;
         return View(confirmedOrder);
     }
     catch (Exception)
     {
         return RedirectToAction("Index", "Error");
     }
 }