public ActionResult Change(ChangeCategoryViewModel model) { if (this.ModelState.IsValid) { var restaurantId = this.User.Identity.GetUserId(); var categoryId = model.CategoryId; this.restaurants.UpdateCategory(categoryId, restaurantId); } var categories = this.Cache.Get("categories", () => this.categories.GetAll().To<CategoryViewModel>().ToList(), CategoriesCacheTime); model.Categories = DropDownListGenerator.GetCategorySelectListItems(categories); return this.View(model); }
public ActionResult Change() { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To<CategoryViewModel>().ToList(), CategoriesCacheTime); var model = new ChangeCategoryViewModel(); var restaurantId = this.User.Identity.GetUserId(); var currentCategoryId = this.restaurants.GetCurrentCategoryId(restaurantId); if (currentCategoryId == null) { currentCategoryId = categories.Where(x => x.Name == "All").FirstOrDefault().Id; this.restaurants.UpdateCategory((int)currentCategoryId, restaurantId); } model.CategoryId = (int)currentCategoryId; model.Categories = DropDownListGenerator.GetCategorySelectListItems(categories); return this.View(model); }
public ActionResult ChangeCategory(ChangeCategoryViewModel updatedCat) { updatedCat.IsValid = ModelState.IsValid; ApplicationUser user = UserManager.FindByName(User.Identity.Name); if (user.Categories.Where(x => x.Name == updatedCat.NewCategoryName).Count() != 0) { ModelState.AddModelError("", "Такая категория уже есть!"); updatedCat.IsValid = false; } if (ModelState.IsValid) { Category categoryToUpdate = user.Categories.FirstOrDefault(x => x.Name == updatedCat.OldCategoryName); categoryToUpdate.Name = updatedCat.NewCategoryName; DbContext.SaveChanges(); updatedCat.IsValid = true; } return(PartialView(updatedCat)); }
public ActionResult Change(ChangeCategoryViewModel model) { if (!this.ModelState.IsValid) { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To <CategoryViewModel>().ToList(), GlobalConstants.CategoriesCacheTimeInSeconds); model.Categories = DropDownListGenerator.GetCategorySelectListItems(categories); this.TempData["SuccessNotification"] = "Restaurant category not changed"; return(this.View(model)); } var restaurantId = this.User.Identity.GetUserId(); var categoryId = model.CategoryId; this.restaurants.UpdateCategory(categoryId, restaurantId); this.TempData["SuccessNotification"] = "Successfuly changed the restaurant category"; return(this.RedirectToAction("Details", "Restaurant", new { area = string.Empty, id = restaurantId })); }
public ActionResult ChangeCategory(string categoryName) { if (string.IsNullOrWhiteSpace(categoryName)) { return(PartialView(new ChangeCategoryViewModel { IsValid = false })); } ApplicationUser user = UserManager.FindByName(User.Identity.Name); var categoryToUpdate = user.Categories.FirstOrDefault(x => x.Name == categoryName); ChangeCategoryViewModel model = new ChangeCategoryViewModel(); model.OldCategoryName = categoryName; if (categoryToUpdate == null) { ModelState.AddModelError("", "Категория не найдена. Как вы это сделали?"); } model.IsValid = false; return(PartialView(model)); }
public ActionResult Change() { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To <CategoryViewModel>().ToList(), GlobalConstants.CategoriesCacheTimeInSeconds); var restaurantId = this.User.Identity.GetUserId(); var currentCategoryId = this.restaurants.GetCurrentCategoryId(restaurantId); if (currentCategoryId == null) { currentCategoryId = categories.Where(x => x.Name == "All").FirstOrDefault().Id; this.restaurants.UpdateCategory((int)currentCategoryId, restaurantId); } var model = new ChangeCategoryViewModel() { CategoryId = (int)currentCategoryId, Categories = DropDownListGenerator.GetCategorySelectListItems(categories) }; return(this.View(model)); }