// GET: Accounts/Details/5 public ActionResult Details(int?id) { if (!Utl.IsLoggedIn(Session) || (!Utl.IsAdmin(Session) && id != null && id != (int)Session["accountID"])) { return(RedirectToAction("Index", "Home")); } if (id == null) { id = (int)Session["accountID"]; } Account account = db.Accounts.Find(id); if (account == null) { return(HttpNotFound()); } account.OrdersHistory = db.OrdersHistories.Where(o => o.AccountID == id).OrderBy(oh => oh.OrderNumber).ToList(); account.OrdersHistory.ForEach(o => o.Product = db.Products.Find(o.ProductID)); return(View(account)); }
public ActionResult Create([Bind(Include = "BranchID,Name,Address,PhoneNumber")] Branch branch) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } bool isNameInDB = db.Branches.Any(a => a.Name == branch.Name && a.BranchID != branch.BranchID); bool isAddressInDB = db.Branches.Any(a => a.Address == branch.Address && a.BranchID != branch.BranchID); if (ModelState.IsValid && !isAddressInDB && !isNameInDB) { db.Branches.Add(branch); db.SaveChanges(); return(RedirectToAction("Index")); } if (isNameInDB) { ViewBag.isNameInDB = isNameInDB; } if (isAddressInDB) { ViewBag.isAddressInDB = isAddressInDB; } return(View(branch)); }
public ActionResult Admin() { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } List <object> productsRates = new List <object>(); var products = db.Products.ToList(); double i = 0; double colorIncrement = 1.0 / products.Count; foreach (var product in products) { productsRates.Add(new { label = product.Name, value = product.PopularityRate, color = "#" + Utl.HSL2RGB(i, 0.5, 0.5).ToString() }); i += colorIncrement; } ViewBag.ProductsRate = productsRates; return(View()); }
// GET: Accounts/Create public ActionResult Create() { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult Create([Bind(Include = "AccountID,IsModerator,Email,Password,Address,PhoneNumber")] Account account) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } return(CreateAccount(account)); }
// GET: Products/Create public ActionResult Create() { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name"); return(View()); }
// GET: Accounts public ActionResult Index(string searchEmail, string searchPhone, string searchAddress, bool?searchIsModerator) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } List <Account> searchProducts = Search(searchEmail, searchPhone, searchAddress, searchIsModerator); return(View(searchProducts)); }
public ActionResult DeleteConfirmed(int id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } Category category = db.Categories.Find(id); db.Categories.Remove(category); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } Account account = db.Accounts.Find(id); db.Accounts.Remove(account); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } Branch branch = db.Branches.Find(id); db.Branches.Remove(branch); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "CategoryID,Name,ImagePath,Description")] Category category) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "CategoryID,Name,ImagePath,Description")] Category category) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
// GET: Branches/Edit/5 public ActionResult Edit(int?id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Branch branch = db.Branches.Find(id); if (branch == null) { return(HttpNotFound()); } return(View(branch)); }
public ActionResult Create([Bind(Include = "ProductID,Name,ImagePath,Description,Price,IsDairy,IsGlutenFree,IsVegan,PopularityRate,CategoryID")] Product product) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", product.CategoryID); return(View(product)); } }
// GET: Accounts/Edit/5 public ActionResult Edit(int?id) { if (!Utl.IsLoggedIn(Session) || ((!Utl.IsAdmin(Session) && id != null && id != (int)Session["accountID"]))) { return(RedirectToAction("Index", "Home")); } if (id == null) { id = (int)Session["accountID"]; } Account account = db.Accounts.Find(id); if (account == null) { return(HttpNotFound()); } return(View(account)); }
// GET: Categories/Edit/5 public ActionResult Edit(int?id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Category category = db.Categories.Find(id); if (category == null) { return(HttpNotFound()); } return(View(category)); }
// GET: Products/Edit/5 public ActionResult Edit(int?id) { if (!Utl.IsAdmin(Session)) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", product.CategoryID); return(View(product)); }
public JsonResult GetOrderHistoryByDate() { if (!Utl.IsAdmin(Session)) { return(Json(new object[] { new object() }, JsonRequestBehavior.AllowGet)); } List <object> orderHistory = new List <object>(); var ohDates = db.OrdersHistories.GroupBy(o => o.OrderDate.Month).ToList(); foreach (var item in ohDates) { orderHistory.Add(new { month = item.Key, ordersNum = item.Count() }); } return(Json(orderHistory, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit([Bind(Include = "AccountID,IsModerator,Email,Password,Address,PhoneNumber")] Account account) { if (!Utl.IsLoggedIn(Session) || (!Utl.IsAdmin(Session) && (int)Session["accountID"] != account.AccountID)) { return(RedirectToAction("Index", "Home")); } bool isEmailInDB = db.Accounts.Any(a => a.Email == account.Email && a.AccountID != account.AccountID); if (!ModelState.IsValid || isEmailInDB) { if (isEmailInDB) { ViewBag.isEmailInDB = isEmailInDB; } return(View(account)); } db.Entry(account).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", "Accounts", new { id = account.AccountID })); }
private bool isAbleToChangeOrder(int accountID) { return(Utl.IsLoggedIn(Session) && (Utl.IsAdmin(Session) || accountID == (int)Session["accountID"])); }