public ActionResult Index() { try { if (Session["User"] == null || Session["UserRole"] == null) { return RedirectToAction("Index", "Home"); } ViewBag.TreeView = "storeInfor"; ViewBag.TreeViewMenu = "storeInforList"; AccountBusiness ab = new AccountBusiness(); StoreInfo storeInfo = db.StoreInfoes.SingleOrDefault(); List<Product> lstNewProduct = db.Products.OrderByDescending(n => n.ProductId).Take(4).ToList(); ViewBag.lstProduct = lstNewProduct; List<Order> lstOrder = db.Orders.Where(n => n.OrderStatus == 0).ToList(); ViewBag.orderWaiting = lstOrder.Count; List<Customer> lstCustomer = db.Customers.ToList(); ViewBag.customer = lstCustomer.Count; List<ProductMaterial> lstLowQuantity = ab.StaffOffLowQuantityNoty(); ViewBag.lowQuantity = lstLowQuantity.Count; return View(storeInfo); } catch { return RedirectToAction("ManageError", "Error"); } }
public int Login(FormCollection f, string strURL) { AccountBusiness ab = new AccountBusiness(); try { string sAccount = f.Get("txtAccount"); string sPassword = f.Get("txtPassword"); User endUser = ab.checkLogin(sAccount, sPassword); if (endUser == null) { return -1; } if (!endUser.IsConfirmed) { ab.ConfirmAccount(endUser.UserId); } if (endUser.RoleId == 3) { if (!endUser.Customers.ElementAt(0).IsActive) { return -2; } Session["User"] = endUser; Session["UserId"] = endUser.UserId; Session["CusUserId"] = endUser.Customers.ElementAt(0).CustomerId; Session["Phonenumber"] = endUser.Customers.ElementAt(0).CustomerPhoneNumber; //Check customer off notifier List<Order> lstNewOrderNoty = ab.CustomerOffNewOrderNoty((int)Session["UserId"]); List<Order> lstEditedOrderNoty = ab.CustomerOffEditedOrderNoty((int)Session["UserId"]); List<Order> lstConfirmOrderNoty = ab.CustomerOffConfirmOrderNoty((int)Session["UserId"]); if (lstNewOrderNoty != null) { Session["CusNewOrderCountPartial"] = Session["CusNotificateCount"] = lstNewOrderNoty.Count; if (lstEditedOrderNoty != null) { Session["CusEditOrderCountPartial"] = lstEditedOrderNoty.Count; Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstEditedOrderNoty.Count; if (lstConfirmOrderNoty != null) { Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count; Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstEditedOrderNoty.Count + lstConfirmOrderNoty.Count; } } else { if (lstConfirmOrderNoty != null) { Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count; Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstConfirmOrderNoty.Count; } } } else { if (lstEditedOrderNoty != null) { Session["CusEditOrderCountPartial"] = Session["CusNotificateCount"] = lstEditedOrderNoty.Count; if (lstConfirmOrderNoty != null) { Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count; Session["CusNotificateCount"] = lstEditedOrderNoty.Count + lstConfirmOrderNoty.Count; } } else { if (lstConfirmOrderNoty != null) { Session["CusConfirmOrderCountPartial"] = Session["CusNotificateCount"] = lstConfirmOrderNoty.Count; } } } //Open connection with this Customer string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId=", endUser.UserId); Session["CheckToNotify"] = endUser.UserId; MvcApplication.changeStatusNotifer.Start("BMAChangeDB", dependencyCheckSql); MvcApplication.changeStatusNotifer.Change += this.OnChange3; return 1; } else { if (endUser.RoleId == 2) { if (!endUser.Staffs.ElementAt(0).IsActive) { return -2; } MvcApplication.notifier.Dispose(); MvcApplication.notifier.Start("BMAChangeDB", "SELECT OrderId FROM dbo.[Orders]"); MvcApplication.notifier.Change += this.OnChange; MvcApplication.lowQuantityNotifer.Dispose(); MvcApplication.lowQuantityNotifer.Start("BMAChangeDB", "SELECT ProductMaterialId,CurrentQuantity,StandardQuantity FROM dbo.[ProductMaterial] WHERE (CurrentQuantity < StandardQuantity AND IsActive = 'True')"); MvcApplication.lowQuantityNotifer.Change += this.OnChange2; //Check staff off notifier List<Order> lstNewOrderNoty = ab.StaffOffNewOrderNoty(); List<Order> lstConfirmOrderNoty = ab.StaffOffConfirmOrderNoty(); List<Order> lstCancelOrderNoty = ab.StaffOffCancelOrderNoty(); List<ProductMaterial> lstLowQuantityNoty = ab.StaffOffLowQuantityNoty(); if (lstNewOrderNoty != null) { Session["NewOrderCountPartial"] = Session["NotificateCount"] = lstNewOrderNoty.Count; if (lstConfirmOrderNoty != null) { Session["ConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count; Session["NotificateCount"] = lstConfirmOrderNoty.Count + lstNewOrderNoty.Count; if (lstCancelOrderNoty != null) { Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count; Session["NotificateCount"] = lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count; if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count; } } else { if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count; } } } else { if (lstCancelOrderNoty != null) { Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count; Session["NotificateCount"] = lstCancelOrderNoty.Count + lstNewOrderNoty.Count; if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstNewOrderNoty.Count; } } else { if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstNewOrderNoty.Count; } } } } else { if (lstConfirmOrderNoty != null) { Session["ConfirmOrderCountPartial"] = Session["NotificateCount"] = lstConfirmOrderNoty.Count; if (lstCancelOrderNoty != null) { Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count; Session["NotificateCount"] = lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count; if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count; } } else { if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstConfirmOrderNoty.Count; } } } else { if (lstCancelOrderNoty != null) { Session["CancelOrderCountPartial"] = Session["NotificateCount"] = lstCancelOrderNoty.Count; if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count; Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count; } } else { if (lstLowQuantityNoty != null) { Session["LowMaterialCountPartial"] = Session["NotificateCount"] = lstLowQuantityNoty.Count; } } } } } Session["User"] = endUser; Session["UserId"] = endUser.UserId; Session["UserRole"] = endUser.Role.RoleId; return 2; } } catch { return -1; } }
public ActionResult ConfigIndex() { try { if (Session["User"] == null || Session["UserRole"] == null) { return RedirectToAction("Index", "Home"); } if ((int)Session["UserRole"] == 2) { return RedirectToAction("Index"); } ViewBag.TreeView = "storeInfor"; ViewBag.TreeViewMenu = "configStoreInfor"; AccountBusiness ab = new AccountBusiness(); List<Product> lstNewProduct = db.Products.OrderBy(n => n.ProductId).Take(4).ToList(); ViewBag.lstProduct = lstNewProduct; List<Order> lstOrder = db.Orders.Where(n => n.OrderStatus == 0).ToList(); ViewBag.orderWaiting = lstOrder.Count; List<Customer> lstCustomer = db.Customers.ToList(); ViewBag.customer = lstCustomer.Count; List<ProductMaterial> lstLowQuantity = ab.StaffOffLowQuantityNoty(); ViewBag.lowQuantity = lstLowQuantity.Count; Policy policy = db.Policies.SingleOrDefault(n => n.PolicyId == 1); ViewBag.minQuantity = policy; Policy policy2 = db.Policies.SingleOrDefault(n => n.PolicyId == 2); ViewBag.maxPrice = policy2; List<DiscountByQuantity> discountByQuantity = db.DiscountByQuantities.ToList(); ViewBag.discountByQuantity = discountByQuantity; var quantityFrom = db.DiscountByQuantities.Select(n => n.QuantityFrom).ToList(); var quantityTo = db.DiscountByQuantities.Select(n => n.QuantityTo).ToList(); var discountRate = db.DiscountByQuantities.Select(n => n.DiscountValue).ToList(); ViewBag.QuantityFrom = quantityFrom; ViewBag.quantityTo = quantityTo; ViewBag.DiscountValue = discountRate; List<Category> category = db.Categories.Where(n => n.CategoryName != "Bánh").ToList(); ViewBag.category = category; return View(); } catch { return RedirectToAction("ManageError", "Error"); } }