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 Edit([Bind(Include = "ID,clientId,CategoryID,Title,Content")] Recipe recipe)
        {
            if (recipe.Content == null || recipe.Title == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                recipe.CreationDate     = DateTime.Now;
                _db.Entry(recipe).State = EntityState.Modified;
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.ClientID   = new SelectList(_db.Clients, "ID", "ClientName", recipe.ClientId);
            ViewBag.CategoryID = new SelectList(_db.Categories, "ID", "Name", recipe.CategoryId);

            return(View(recipe));
        }
Exemple #3
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 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"));
        }
Exemple #5
0
        public ActionResult Create()
        {
            if (AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(View());
            }

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

            return(RedirectToAction("Index", "Home"));
        }
Exemple #7
0
        public ActionResult Create()
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName");
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content");

            return(View());
        }
Exemple #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var comment = _db.Comments.Find(id);

            _db.Comments.Remove(comment);
            _db.SaveChanges();

            return(RedirectToAction("Index", "Recipes"));
        }
Exemple #9
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"));
        }
Exemple #11
0
        public ActionResult Create([Bind(Include = "ID,ClientID,RecipeID,Content,CreationDate")] Comment comment)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                _db.Comments.Add(comment);
                _db.SaveChanges();

                return(RedirectToAction("Index", "Recipes"));
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
Exemple #12
0
        public ActionResult Delete(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

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

            var comment = _db.Comments.Find(id);

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

            return(View(comment));
        }
Exemple #13
0
        public ActionResult Edit([Bind(Include = "ID,RecipeID,ClientId,Content,Score")] Comment comment)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                comment.CreationDate     = DateTime.Now;
                _db.Entry(comment).State = EntityState.Modified;
                _db.SaveChanges();

                return(RedirectToAction("Index", "Recipes"));
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
        public ActionResult PostComment(int clientId, int recipeId, string content, int score)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var comment = new Comment
            {
                Content      = content,
                Score        = score,
                ClientId     = clientId,
                RecipeId     = recipeId,
                CreationDate = DateTime.Now
            };

            _db.Comments.Add(comment);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #15
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));
        }
Exemple #16
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"));
        }
Exemple #17
0
        public ActionResult Edit(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

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

            var comment = _db.Comments.Find(id);

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

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
        public ActionResult Edit(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

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

            var recipe = _db.Recipes.Find(id);

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

            ViewBag.ClientID   = new SelectList(_db.Clients, "ID", "ClientName", recipe.ClientId);
            ViewBag.CategoryID = new SelectList(_db.Categories, "ID", "Name", recipe.CategoryId);

            return(View(recipe));
        }