예제 #1
0
        public ActionResult Create([Bind(Include = "AccountID,IsModerator,Email,Password,Address,PhoneNumber")] Account account)
        {
            if (!Utl.IsAdmin(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(CreateAccount(account));
        }
예제 #2
0
        // GET: Accounts/Create
        public ActionResult Create()
        {
            if (!Utl.IsAdmin(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
예제 #3
0
        // GET: Products/Create
        public ActionResult Create()
        {
            if (!Utl.IsAdmin(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name");
            return(View());
        }
예제 #4
0
        // 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));
        }
예제 #5
0
        /********
         *
         * Logout
         *
         * ********/
        // GET: Accounts/Logout
        public ActionResult LogOut()
        {
            if (Utl.IsLoggedIn(Session))
            {
                Session["accountID"] = null;
                Session["cart"]      = null;
                Session.Clear();
                Session.Abandon();
            }

            return(RedirectToAction("Index", "Home"));
        }
        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"));
        }
예제 #7
0
        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"));
        }
예제 #8
0
        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 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));
        }
예제 #10
0
        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));
        }
예제 #11
0
        public ActionResult AddItem(int accountID, int productID, int amount)
        {
            if (!isAbleToChangeOrder(accountID))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var accountOrders = getAccountsOrders(accountID);

            addItemToDB(accountID, productID, amount, accountOrders);

            db.SaveChanges();
            Session["cart"] = Utl.CreateCart(Session, accountOrders.ToList());

            return(RedirectToAction("Index", "Home"));
        }
예제 #12
0
        public ActionResult Register([Bind(Include = "AccountID,IsModerator,Email,Password,Address,PhoneNumber")] Account account)
        {
            if (Utl.IsLoggedIn(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            List <object> errorMessages = accountDetailsValidation(account.Email, account.Password, account.Address, account.PhoneNumber);

            if (errorMessages.Count > 0)
            {
                return(Json(errorMessages));
            }

            CreateAccount(account);
            return(Login(account.Email, account.Password));
        }
예제 #13
0
        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));
            }
        }
예제 #14
0
        // 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));
        }
예제 #15
0
        public ActionResult SubmitOrder()
        {
            if (!Utl.IsLoggedIn(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            int accountID = (int)Session["accountID"];

            Account account = db.Accounts.FirstOrDefault(a => a.AccountID == accountID);

            if (account == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var order = db.Orders.Include(o => o.Product).Include(o => o.Account).Where(o => o.AccountID == account.AccountID).ToList();

            if (order == null || order.Count == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            int orderNumber = 1;

            if (db.OrdersHistories.Count() > 0)
            {
                orderNumber += db.OrdersHistories.Max(o => o.OrderNumber);
            }

            foreach (Order item in order)
            {
                db.Products.Find(item.ProductID).PopularityRate += item.Amount;
                archiveItemFromOrder(item, orderNumber);
            }

            db.SaveChanges();
            Session["cart"] = null;

            return(RedirectToAction("Details", "Accounts", new { id = (int)Session["accountID"] }));
        }
예제 #16
0
        // 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));
        }
예제 #17
0
        // GET: Products/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            int?accountID = Utl.IsLoggedIn(Session) ? (int)Session["accountID"] : -1;
            var prefs     = Utl.Preferences(accountID, (int)id);

            ViewBag.Preferences  = Utl.PopulateProducts(prefs);
            ViewBag.CategoryName = db.Categories.Where(c => c.CategoryID == product.CategoryID).ToList()[0].Name;
            return(View(product));
        }
예제 #18
0
        // 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));
        }
예제 #19
0
        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));
        }
예제 #20
0
        // 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));
        }
예제 #21
0
        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 }));
        }
예제 #22
0
        public ActionResult UpdateItem(int accountID, int productID, int amount)
        {
            if (!isAbleToChangeOrder(accountID))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var accountOrders = getAccountsOrders(accountID);

            if (accountOrders.Any(o => o.ProductID == productID))
            {
                updateItemInDB(accountID, productID, amount);
            }
            else
            {
                addNewItemToDB(accountID, productID, amount);
            }

            db.SaveChanges();
            Session["cart"] = Utl.CreateCart(Session, accountOrders.ToList());

            return(RedirectToAction("Index", "Home"));
        }
예제 #23
0
 private bool isAbleToChangeOrder(int accountID)
 {
     return(Utl.IsLoggedIn(Session) && (Utl.IsAdmin(Session) || accountID == (int)Session["accountID"]));
 }