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")); }
public ActionResult Create() { if (AuthorizationMiddleware.AdminAuthorized(Session)) { return(View()); } return(RedirectToAction("Index", "Home")); }
// GET: Catgories public ActionResult Index() { if (AuthorizationMiddleware.AdminAuthorized(Session)) { return(View(_db.Categories.ToList())); } return(RedirectToAction("Index", "Home")); }
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")); }
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)); }
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")); }