public ViewResult CreateRecipeSmallCategory() { var viewModel = new InsertRecipeSmallCategoryViewModel { RecipeSmallCategory = new RecipeSmallCategory(), RecipeCategory = new List<CheckedRecipeCategory>(), TipCategories = PrepareTipCategories()}; foreach (var recipeCategory in ReferenceDataCache.RecipeCategoryCollection) { viewModel.RecipeCategory.Add(new CheckedRecipeCategory { RecipeCategory = recipeCategory }); } return View(viewModel); }
public ActionResult EditRecipeSmallCategory(InsertRecipeSmallCategoryViewModel vm) { if (ModelState.IsValid) { // Generate Url friendly name vm.RecipeSmallCategory.NameUrl = vm.RecipeSmallCategory.Name.ToUrlFriendly(); IList<int> c = (from t in vm.RecipeCategory where t.IsChecked select t.RecipeCategory.Id).ToList(); // Call repository to perform insert Feedback<RecipeSmallCategory> feedback = _recipeSmallRepository.UpdateRecipeSmallCategory(vm.RecipeSmallCategory, c); if (feedback.Success) { // Replace current TipCategory in cache by updated one RecipeSmallCategory exist = ReferenceDataCache.RecipeSmallCategoryCollection.FirstOrDefault(i => i.Id == feedback.Data.Id); if (exist != null) { // Remove Collection from cache to force reload on next access Cacher.Remove(Constants.ConfigKeys.Caching.RecipeSmallCategoryCollectionCacheMinutes); Cacher.Remove(Constants.ConfigKeys.Caching.RecipeAllCategoryCollectionCacheMinutes); SetMessage("Small Recipe Category has been updated successfully", MessageType.Success); return RedirectToAction("ManageRecipeSmallCategories"); } } else { SetMessage(feedback.Message, MessageType.Error); } } vm.TipCategories = PrepareTipCategories(); return View(vm); }