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"); } }
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; } }
// 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"); } }