Example #1
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;
     }
 }
Example #2
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;
     }
 }
Example #3
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;
            }
        }