public int CancelBothOrder(int orderId)
 {
     try
     {
         CusManageBusiness cmb = new CusManageBusiness();
         var orderCheck = cmb.GetOrderDetail(orderId);
         if (orderCheck.CustomerUserId != Convert.ToInt32(Session["UserId"]))
         {
             return -2;
         }
         OrderBusiness ob = new OrderBusiness();
         int userId = Convert.ToInt32(Session["UserId"]);
         if (orderCheck.OrderStatus != 0)
         {
             string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderId FROM dbo.[Orders] WHERE CustomerUserId = ", userId);
             MvcApplication.lowQuantityNotifer.Dispose();
             MvcApplication.cancelOrderNotifier.Start("BMAChangeDB", dependencyCheckSql);
             MvcApplication.cancelOrderNotifier.Change += this.CancelOnChange;
         }
         ob.Cancel(orderId, 0, 0, userId);
         //MvcApplication.lowQuantityNotifer.Start("BMAChangeDB", "SELECT ProductMaterialId,CurrentQuantity,StandardQuantity FROM dbo.[ProductMaterial] WHERE (CurrentQuantity < StandardQuantity AND IsActive = 'True')");
         //MvcApplication.lowQuantityNotifer.Change += this.OnChange2;
         return 1;
     }
     catch (DataException)
     {
         return -1;
     }
 }
Example #2
0
 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     InputMaterialBusiness business = new InputMaterialBusiness();
     business.CheckInputMaterialListStartup();
     // Auto remove order if delivery date < Today
     OrderBusiness orderBusiness = new OrderBusiness();
     orderBusiness.AutoRemoveWaitingOrder();
 }
Example #3
0
        public ActionResult Add()
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return RedirectToAction("Index", "Home");
                }

                OrderBusiness orderBusiness = new OrderBusiness();
                InitiateProductList(null);
                ViewBag.MinQuantity = orderBusiness.GetMinQuantity();
                ViewBag.MaxPrice = orderBusiness.GetMaxPrice();
                ViewBag.TreeView = "order";
                ViewBag.TreeViewMenu = "addOrder";
                return View();
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
Example #4
0
        public int Edit(FormCollection form)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return -7;
                }
                else
                {
                    string orderIdString = form["orderId"];
                    string[] productIdString = Regex.Split(form["productId"], ",");
                    string[] priceString = Regex.Split(form["productPrice"], ",");
                    string[] quantityString = Regex.Split(form["productQuantity"], ",");
                    string depositAmountString = form["depositAmount"];
                    string deliveryDateString = form["deliveryDate"];
                    string orderNote = form["orderNote"];

                    List<CartViewModel> cartList = new List<CartViewModel>();
                    int totalQuantity = 0;
                    if (productIdString.Length == priceString.Length && priceString.Length == quantityString.Length)
                    {
                        for (int i = 0; i < productIdString.Length; i++)
                        {
                            CartViewModel cartViewModel = new CartViewModel();
                            cartViewModel.ProductId = Convert.ToInt32(productIdString[i]);
                            cartViewModel.RealPrice = Convert.ToInt32(priceString[i]);
                            int quantity = Convert.ToInt32(quantityString[i]);
                            cartViewModel.Quantity = quantity;
                            totalQuantity += quantity;
                            cartList.Add(cartViewModel);
                        }
                    }
                    if (totalQuantity == 0)
                    {
                        return -1;
                    }
                    OrderBusiness orderBusiness = new OrderBusiness(); ;
                    int minQuantity = orderBusiness.GetMinQuantity();
                    if (totalQuantity < minQuantity)
                    {
                        ViewBag.MinQuantity = minQuantity;
                        return -2;
                    }
                    int orderId = Convert.ToInt32(orderIdString);
                    int depositAmount = Convert.ToInt32(depositAmountString.Replace(".", ""));
                    DateTime deliveryDate = DateTime.ParseExact(deliveryDateString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

                    //Manh code them
                    Order order = db.Orders.SingleOrDefault(n => n.OrderId == orderId);
                    int cusUserId = order.CustomerUserId.Value;
                    Session["TempCusUserId"] = cusUserId;
                    MvcApplication.changeStatusNotifer.Dispose();
                    string dependencyCheckSql = string.Format("{0}{1}{2}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId = ", cusUserId, " AND OrderStatus = 1");
                    MvcApplication.confirmToCustomerNotifer.Start("BMAChangeDB", dependencyCheckSql);
                    MvcApplication.confirmToCustomerNotifer.Change += this.OnChange6;
                    //het

                    int rs = orderBusiness.UpdateOrder(cartList, orderId, depositAmount, deliveryDate, staffUser.UserId, orderNote);
                    if (rs == 1)
                    {
                        Session["ProductList"] = null;
                    }

                    return rs;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #5
0
        // GET: Edit
        public ActionResult Edit(int id)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return RedirectToAction("Index", "Home");
                }

                OrderBusiness orderBusiness = new OrderBusiness();
                int minQuantity = orderBusiness.GetMinQuantity();
                ViewBag.MinQuantity = minQuantity;

                List<DiscountByQuantity> discountByQuantityList = orderBusiness.GetDiscountByQuantityList();
                if (discountByQuantityList != null && discountByQuantityList.Count != 0)
                {
                    ViewBag.DiscountByQuantityList = discountByQuantityList;
                }

                OrderViewModel orderViewModel = orderBusiness.GetOrderViewModel(id);
                TaxRate taxRate = db.TaxRates.FirstOrDefault(m => m.TaxTypeId == 1 && m.EndDate >= DateTime.Now && m.BeginDate <= DateTime.Now);
                if (taxRate != null)
                {
                    orderViewModel.TaxRate = taxRate.TaxRateValue;
                }
                if (orderViewModel == null)
                {
                    return RedirectToAction("ManageError", "Error");
                }
                if (orderViewModel.Order.OrderStatus == 0 && !orderViewModel.Order.CustomerEditingFlag)
                {
                    if (!orderViewModel.IsEnoughMaterial)
                    {
                        ViewBag.ShortageOfMaterial = true;
                    }
                    ViewBag.Title = "Chỉnh sửa đơn hàng";
                    ViewBag.TreeView = "order";
                    InitiateProductList(orderViewModel.Order.OrderId);
                    return View(orderViewModel);
                }
                return RedirectToAction("ManageError", "Error");
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
Example #6
0
 // GET: Detail
 public ActionResult Detail(int id)
 {
     try
     {
         // Check autherization
         User staffUser = Session["User"] as User;
         if (staffUser == null || Session["UserRole"] == null)
         {
             return RedirectToAction("Index", "Home");
         }
         OrderBusiness orderBusiness = new OrderBusiness();
         OrderViewModel orderViewModel = orderBusiness.GetOrderViewModel(id);
         if (orderViewModel == null)
         {
             return RedirectToAction("ManageError", "Error");
         }
         ViewBag.TreeView = "order";
         ViewBag.TaxRate = orderBusiness.GetVatRateAtTime(orderViewModel.Order.CreateTime);
         if (!orderViewModel.IsEnoughMaterial)
         {
             ViewBag.ShortageOfMaterial = true;
         }
         return View(orderViewModel);
     }
     catch (Exception)
     {
         return RedirectToAction("ManageError", "Error");
     }
 }
Example #7
0
        public ActionResult CheckoutWithNewCustomer(FormCollection form)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    Session["Cart"] = null;
                    return RedirectToAction("Index", "Home");
                }

                List<CartViewModel> inputCartList = Session["Cart"] as List<CartViewModel>;

                string customerNameString = form["customerName"];
                string customerEmailString = form["customerEmail"];
                string customerAddressString = form["customerAddress"];
                string customerPhoneNumberString = form["customerPhoneNumber"];
                string customerTaxCodeString = form["customerTaxCode"];
                string usernameString = form["username"];
                if (
                    !(customerNameString.IsEmpty() || customerAddressString.IsEmpty() || customerPhoneNumberString.IsEmpty() ||
                      customerTaxCodeString.IsEmpty() || customerEmailString.IsEmpty() || usernameString.IsEmpty()))
                {
                    CustomerViewModel customer = new CustomerViewModel();
                    customer.CustomerName = customerNameString;
                    customer.CustomerAddress = customerAddressString;
                    customer.CustomerPhoneNumber = customerPhoneNumberString;
                    customer.CustomerTaxCode = customerTaxCodeString;
                    customer.Username = usernameString;
                    customer.CustomerEmail = customerEmailString;
                    Session["CustomerId"] = 0;
                    Session["NewCustomer"] = customer;
                    OrderBusiness orderBusiness = new OrderBusiness();
                    OrderViewModel order = orderBusiness.MakeOrderViewModel(inputCartList, null, customer);
                    ViewBag.TreeView = "order";
                    ViewBag.TreeViewMenu = "addOrder";
                    return View("CheckoutWithCustomer", order);
                }
                return RedirectToAction("AddCustomerToOrder");
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
 public ActionResult CancelOrderConfirm(int orderId, string strURL)
 {
     try
     {
         CusManageBusiness cmb = new CusManageBusiness();
         var orderCheck = cmb.GetOrderDetail(orderId);
         if (orderCheck.CustomerUserId != Convert.ToInt32(Session["UserId"]))
         {
             return RedirectToAction("Index", "Home");
         }
         OrderBusiness ob = new OrderBusiness();
         int userId = Convert.ToInt32(Session["UserId"]);
         if (orderCheck.OrderStatus != 0)
         {
             string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderId FROM dbo.[Orders] WHERE CustomerUserId = ", userId);
             MvcApplication.lowQuantityNotifer.Dispose();
             MvcApplication.cancelOrderNotifier.Start("BMAChangeDB", dependencyCheckSql);
             MvcApplication.cancelOrderNotifier.Change += this.CancelOnChange;
         }
         ob.Cancel(orderId, 0, 0, userId);
         return Redirect(strURL);
     }
     catch (DataException)
     {
         return RedirectToAction("Index");
     }
 }
Example #9
0
        // GET: Order
        public ActionResult Index(string fromDate, string toDate, string customerName, int? orderStatus)
        {
            try
            {
                // Dispose notificate and reinitial
                if (Session["TempCusUserId"] != null)
                {
                    int userId = (int)Session["TempCusUserId"];
                    if (!MvcApplication.changeStatusNotifer.CheckConnection())
                    {
                        string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId=", userId);
                        Session["CheckToNotify"] = userId;
                        MvcApplication.changeStatusNotifer.Start("BMAChangeDB", dependencyCheckSql);
                        MvcApplication.changeStatusNotifer.Change += this.OnChange3;
                    }

                    MvcApplication.confirmToCustomerNotifer.Dispose();
                    Session["TempCusUserId"] = null;
                }
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null)
                {
                    return RedirectToAction("Index", "Home");
                }
                Session["Cart"] = null;
                ViewBag.TreeView = "order";
                ViewBag.TreeViewMenu = "orderList";
                ViewBag.Title = "Danh sách đơn hàng";

                OrderBusiness orderBusiness = new OrderBusiness();
                List<OrderViewModel> orderViewModelList;
                if (fromDate != null && !fromDate.Trim().IsEmpty() && toDate != null && !toDate.Trim().IsEmpty())
                {
                    DateTime FromDate = DateTime.ParseExact(fromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    DateTime ToDate = DateTime.ParseExact(toDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    orderViewModelList = orderBusiness.GetSortedOrderViewModelList(FromDate, ToDate, customerName, orderStatus);
                }
                else
                {
                    orderViewModelList = orderBusiness.GetSortedOrderViewModelList(null, null, customerName, orderStatus);
                }

                if (orderViewModelList == null)
                {
                    return RedirectToAction("ManageError", "Error");
                }
                ViewBag.Title = "Danh sách đơn hàng";
                ViewBag.FromDate = fromDate;
                ViewBag.ToDate = toDate;
                ViewBag.CustomerName = customerName;
                ViewBag.OrderStatus = orderStatus;
                return View(orderViewModelList);

            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
Example #10
0
        public int AddOrderForCustomer(FormCollection form)
        {
            try
            {
                int deposit = Convert.ToInt32(form["deposit"].Replace(".", ""));
                string deliveryDate = form["deliveryDate"];
                int customerId = Convert.ToInt32(form["customerId"]);
                string orderNote = form["orderNote"];
                //Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return -7;
                }
                else
                {
                    int rs = 0;
                    List<CartViewModel> cart = Session["Cart"] as List<CartViewModel>;

                    DateTime deliveryDate1 = DateTime.ParseExact(deliveryDate, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

                    if (customerId == 0)
                    {
                        CustomerViewModel customer = Session["NewCustomer"] as CustomerViewModel;
                        OrderBusiness orderBusiness = new OrderBusiness();
                        bool check = orderBusiness.AddOrder(cart, null, customer, staffUser.UserId, deposit, deliveryDate1, orderNote);
                        if (check)
                        {
                            rs = 1;
                        }
                    }
                    else
                    {
                        OrderBusiness orderBusiness = new OrderBusiness();
                        bool check = orderBusiness.AddOrder(cart, customerId, null, staffUser.UserId, deposit, deliveryDate1, orderNote);
                        if (check)
                        {
                            rs = 1;
                        }
                    }
                    if (rs == 1)
                    {
                        Session["CustomerId"] = null;
                        Session["NewCustomer"] = null;
                        Session["Cart"] = null;
                    }
                    return rs;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #11
0
        public int Cancel(int orderId, int isReturnDeposit, int returnDeposit, string url)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return -7;
                }

                OrderBusiness orderBusiness = new OrderBusiness();
                bool rs = orderBusiness.Cancel(orderId, returnDeposit, isReturnDeposit, staffUser.UserId);
                return rs ? 1 : 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #12
0
        public int ApproveOrder(FormCollection form)
        {
            try
            {
                //Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return -7;
                }
                else
                {
                    String customerName = form["customerName"];

                    if (customerName == null)
                    {

                        int orderId = Convert.ToInt32(form["orderId"]);
                        int deposit = Convert.ToInt32(form["deposit"].Replace(".", ""));
                        string deliveryDateString = form["deliveryDate"];
                        DateTime deliveryDate = DateTime.ParseExact(deliveryDateString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

                        OrderBusiness orderBusiness = new OrderBusiness();

                        return orderBusiness.ApproveOrder(orderId, deposit, deliveryDate, staffUser.UserId, null);
                    }
                    else
                    {
                        string orderIdString = form["orderId"];
                        string username = form["username"];
                        string email = form["customerEmail"];
                        string customerAddress = form["customerAddress"];
                        string customerPhoneNumber = form["customerPhoneNumber"];
                        string customerTaxCode = form["customerTaxCode"];
                        if (!(customerName.IsEmpty() || orderIdString.IsEmpty() || username.IsEmpty() || email.IsEmpty() ||
                              customerAddress.IsEmpty() || customerPhoneNumber.IsEmpty() || customerTaxCode.IsEmpty()))
                        {
                            OrderBusiness orderBusiness = new OrderBusiness();
                            int check = orderBusiness.CheckCustomerField(email, customerAddress, customerPhoneNumber,
                                customerTaxCode, username);
                            if (check != 0)
                            {
                                return check;
                            }

                            int orderId = Convert.ToInt32(orderIdString);
                            int deposit = Convert.ToInt32(form["deposit"].Replace(".", ""));

                            CustomerViewModel customer = new CustomerViewModel
                            {
                                Username = username,
                                CustomerEmail = email,
                                CustomerAddress = customerAddress,
                                CustomerPhoneNumber = customerPhoneNumber,
                                CustomerName = customerName,
                                CustomerTaxCode = customerTaxCode
                            };

                            DateTime deliveryDate = DateTime.ParseExact(form["deliveryDate"], "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);

                            int rs = orderBusiness.ApproveOrder(orderId, deposit, deliveryDate, staffUser.UserId, customer);
                            return rs;
                        }
                        return 0;
                    }
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #13
0
        public int AddToCart(int[] productId, int[] productQuantity, int[] productPrice)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return 0;
                }

                List<CartViewModel> cartList = new List<CartViewModel>();
                if (productId != null && productQuantity != null && productPrice != null && productId.Length > 0 &&
                    productQuantity.Length > 0 && productPrice.Length > 0 && productId.Length == productQuantity.Length && productQuantity.Length == productPrice.Length)
                {
                    for (int i = 0; i < productId.Length; i++)
                    {
                        OrderBusiness orderBusiness = new OrderBusiness();
                        Product product = orderBusiness.GetProductById(productId[i]);
                        if (productQuantity[i] > 0)
                        {
                            CartViewModel cartViewModel = new CartViewModel
                            {
                                ProductId = productId[i],
                                ProductName = product.ProductName,
                                Quantity = productQuantity[i],
                                RealPrice = productPrice[i],
                                StandardPrice = product.ProductStandardPrice
                            };
                            cartList.Add(cartViewModel);
                        }
                    }
                }
                if (cartList.Count > 0)
                {
                    Session["Cart"] = cartList;
                    return 1;
                }
                return 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public ActionResult AddInputBill()
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    try
                    {
                        ViewBag.TreeView = "inputBill";
                        ViewBag.TreeViewMenu = "addInputBill";

                        OrderBusiness business = new OrderBusiness();
                        ViewBag.TaxRate = business.GetVatRateAtTime(DateTime.Now);

                        List<InputBill> inputBills = db.InputBills.ToList();
                        return View(inputBills);
                    }
                    catch (Exception)
                    {
                        return RedirectToAction("ManageError", "Error");
                    }
                }
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
 public ActionResult EditInputBill(int id)
 {
     try
     {
         User staffUser = Session["User"] as User;
         if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
         {
             return RedirectToAction("Index", "Home");
         }
         else
         {
             try
             {
                 ViewBag.TreeView = "inputBill";
                 OrderBusiness business = new OrderBusiness();
                 ViewBag.TaxRate = business.GetVatRateAtTime(DateTime.Now);
                 InputBill inputBill = db.InputBills.SingleOrDefault(m => m.InputBillId == id);
                 if (inputBill == null)
                 {
                     return RedirectToAction("InputBillIndex", "InputBill");
                 }
                 else return View(inputBill);
             }
             catch (Exception)
             {
                 return RedirectToAction("ManageError", "Error");
             }
         }
     }
     catch (Exception)
     {
         return RedirectToAction("ManageError", "Error");
     }
 }
Example #16
0
        public ActionResult ExportBill(int orderId)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null)
                {
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    OrderBusiness orderBusiness = new OrderBusiness();
                    Order order = orderBusiness.GetOrder(orderId);
                    // Get tax rate
                    TaxRate taxRate = db.TaxRates.FirstOrDefault(m => m.EndDate >= order.CreateTime && m.BeginDate <= order.CreateTime);
                    if (taxRate != null)
                    {
                        ViewBag.TaxRate = taxRate.TaxRateValue;
                    }

                    // Get store info

                    StoreInfo storeInfo = db.StoreInfoes.FirstOrDefault();
                    if (storeInfo != null)
                    {
                        ViewBag.StoreInfo = storeInfo;
                    }

                    // Get Manager Name
                    User user = db.Users.FirstOrDefault(m => m.Role.Name.Contains("Manager"));
                    if (user != null)
                    {
                        ViewBag.ManagerName = user.Fullname;
                    }

                    // Bug check order is null or not.
                    return View(order);
                }
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
Example #17
0
        public int ExportMaterial(FormCollection form)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return 0;
                }

                string productMaterialIdString = form["productMaterialId"];
                string outputMaterialIdString = form["outputMaterialId"];
                string exportQuantityString = form["exportQuantity"];

                int productMaterialId = Convert.ToInt32(productMaterialIdString);
                int outputMaterialId = Convert.ToInt32(outputMaterialIdString);
                int exportQuantity = Convert.ToInt32(exportQuantityString);

                OrderBusiness business = new OrderBusiness();

                return business.ExportMaterial(productMaterialId, outputMaterialId, exportQuantity) ? 1 : 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #18
0
        public int ChangeOrderState(int orderId)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return 0;
                }

                OrderBusiness orderBusiness = new OrderBusiness();
                if (orderBusiness.ChangeOrderState(orderId))
                {
                    return 1;
                }
                return 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #19
0
        public ActionResult GetShortageMaterialList()
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return null;
                }

                OrderBusiness orderBusiness = new OrderBusiness();
                List<ShortageMaterialViewModel> shortageMaterialList =
                    orderBusiness.GetShortageMaterialList();
                return PartialView(shortageMaterialList);
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #20
0
        public int CheckCustomerField(FormCollection form)
        {
            try
            {
                string customerEmailString = form["customerEmail"];
                string customerAddressString = form["customerAddress"];
                string customerPhoneNumberString = form["customerPhoneNumber"];
                string customerTaxCodeString = form["customerTaxCode"];
                string usernameString = form["username"];

                OrderBusiness orderBusiness = new OrderBusiness();
                return orderBusiness.CheckCustomerField(customerEmailString, customerAddressString, customerPhoneNumberString, customerTaxCodeString, usernameString);
            }
            catch (Exception)
            {
                return 0;
            }
        }
Example #21
0
        public ActionResult UpdateMaterialList(FormCollection form)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return null;
                }

                string[] productIdString = Regex.Split(form["productId"], ",");
                string[] priceString = Regex.Split(form["productPrice"], ",");
                string[] quantityString = Regex.Split(form["productQuantity"], ",");
                string orderIdString = form["orderId"];
                List<CartViewModel> cartList = new List<CartViewModel>();
                if (productIdString.Length == priceString.Length && priceString.Length == quantityString.Length)
                {
                    for (int i = 0; i < productIdString.Length; i++)
                    {
                        CartViewModel cartViewModel = new CartViewModel();
                        cartViewModel.ProductId = Convert.ToInt32(productIdString[i]);
                        cartViewModel.RealPrice = Convert.ToInt32(priceString[i]);
                        cartViewModel.Quantity = Convert.ToInt32(quantityString[i]);
                        cartList.Add(cartViewModel);
                    }
                }
                if (cartList.Count > 0)
                {
                    OrderBusiness orderBusiness = new OrderBusiness();
                    MaterialInfoForProductListViewModel material = orderBusiness.GetMaterialListForOrder(cartList);
                    material.OrderId = Convert.ToInt32(orderIdString);
                    return PartialView("MaterialListForOrder", material);
                }
                return PartialView("MaterialListForOrder", null);
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #22
0
        public ActionResult CheckoutWithCustomer(int customerId)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    Session["Cart"] = null;
                    return RedirectToAction("Index", "Home");
                }

                List<CartViewModel> inputCartList = Session["Cart"] as List<CartViewModel>;
                OrderBusiness orderBusiness = new OrderBusiness();
                OrderViewModel order = orderBusiness.MakeOrderViewModel(inputCartList, customerId, null);
                if (!order.IsEnoughMaterial)
                {
                    ViewBag.ShortageOfMaterial = true;
                }
                ViewBag.TaxRate = orderBusiness.GetVatRateAtTime(DateTime.Now);
                Session["CustomerId"] = customerId;
                ViewBag.TreeView = "order";
                ViewBag.TreeViewMenu = "addOrder";
                return View(order);
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }