Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var category = _db.Categories.Find(id);
            var recipes  = _db.Recipes.Where(x => x.Category.Id == id).ToList();

            foreach (var currRecipe in recipes)
            {
                var recipe = _db.Recipes.Find(currRecipe.Id);

                var commentsToRemove = _db.Comments.Where(x => x.RecipeId == currRecipe.Id).ToList();

                foreach (var currComment in commentsToRemove)
                {
                    _db.Comments.Remove(currComment);
                }

                _db.Recipes.Remove(recipe);
            }

            _db.Categories.Remove(category);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Search(string username, string firstname, string lastname)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var requestedClients = new List <Client>();

            foreach (var client in _db.Clients)
            {
                if (!string.IsNullOrEmpty(username) && client.ClientName.Contains(username))
                {
                    requestedClients.Add(client);
                }
                else if (!string.IsNullOrEmpty(firstname) && client.FirstName.Contains(firstname))
                {
                    requestedClients.Add(client);
                }
                else if (!string.IsNullOrEmpty(lastname) && client.LastName.Contains(lastname))
                {
                    requestedClients.Add(client);
                }
            }

            return(View(requestedClients.OrderByDescending(x => x.ClientName)));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var client = _db.Clients.Find(id);

            var recipes = _db.Recipes.Where(x => x.ClientId == id).ToList();

            foreach (var currComment in _db.Comments.Where(x => x.ClientId == id).ToList())
            {
                _db.Comments.Remove(currComment);
            }

            foreach (var currRecipe in recipes)
            {
                _db.Recipes.Remove(currRecipe);
            }

            _db.Clients.Remove(client);
            _db.SaveChanges();

            if (((Client)Session["Client"]).Id == id)
            {
                Session.Clear();
            }

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Create()
        {
            if (AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(View());
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #5
0
        // GET: Catgories
        public ActionResult Index()
        {
            if (AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(View(_db.Categories.ToList()));
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #6
0
        public ActionResult Edit([Bind(Include = "ID,Name")] Category category)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(category));
            }

            _db.Entry(category).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "ID,Gender,ClientName,FirstName,LastName,Password,isAdmin")] Client client)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(client));
            }

            _db.Entry(client).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public ActionResult Edit(int?id)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var category = _db.Categories.Find(id);

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

            return(View(category));
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "ID,Name")] Category category)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(category));
            }

            var requestedCategory = _db.Categories.FirstOrDefault(x => x.Name == category.Name);

            if (requestedCategory != null)
            {
                return(View(category));
            }

            _db.Categories.Add(category);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }