Пример #1
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;
     }
 }
Пример #2
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;
     }
 }