public IActionResult Edit(CategoryEditInputModel model) { if (!this.categoryService.Exists(model.Id)) { return(this.BadRequest()); } if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } var editCategoryServiceModel = new EditCategoryServiceModel() { Id = model.Id, Name = model.Name, Description = model.Description }; this.categoryService.Edit(editCategoryServiceModel); return(this.RedirectToAction("Details", "Categories", new { id = editCategoryServiceModel.Id })); }
public async Task <IActionResult> Edit(CategoryEditInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoryService.UpdateAsync(input.Id, input.Name, input.Description); return(this.RedirectToAction("Id", "Categories", new { area = string.Empty, input.Id })); }
public async Task <IActionResult> Edit(CategoryEditInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoryService.EditAsync(input.Id, input.Name); return(this.RedirectToAction(nameof(this.Index))); }
public ActionResult Edit(int id, CategoryEditInputModel model) { if (ModelState.IsValid) { var edited = this.CategoryService.Edit(id, model); if (edited) { return(RedirectToAction(GlobalConstants.IndexPage)); } } return(this.View(model)); }
public async Task <IActionResult> Edit(CategoryEditInputModel categoryEditInputModel) { if (!this.ModelState.IsValid) { return(this.View(categoryEditInputModel)); } if (!await this.categoryService.EditCategory(categoryEditInputModel)) { this.TempData["Error"] = ValidationMessages.CategoryUniqieNameErrorMessage; return(this.RedirectToAction("Edit", "Categories", new { categoryId = categoryEditInputModel.Id })); } return(this.RedirectToAction("All")); }
public async Task <IActionResult> Edit(CategoryEditInputModel editInputModel) { if (!this.ModelState.IsValid) { this.ViewData["mainCategories"] = this.mainCategoryService .GetAllMainCategories() .To <CreateCategoryMainCategoryViewModel>(); return(this.View(editInputModel)); } await this.categoryService.EditCategoryAsync(editInputModel.To <CategoryServiceModel>()); return(this.RedirectToAction("All", "Categories")); }
public bool Edit(int id, CategoryEditInputModel model) { try { var catToEdit = this.Data.Categories.GetById(id); Mapper.Map(model, catToEdit); this.Data.Categories.Update(catToEdit); this.Data.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> Edit(CategoryEditInputModel input) { if (!this.categoriesService.CategoryExists(input.Id)) { return(this.View(GlobalConstants.NotFoundRoute)); } if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoriesService.EditAsync(input.Id, input.Name, input.ImageUrl, input.Description); return(this.Redirect("/Administration/Categories")); }
public async Task EditCategory_ThrowException_WhenCategoryDoesntExist() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoryService = new CategoryService(categoryRepository); var inputModel = new CategoryEditInputModel() { Id = "1", Name = "invalid", }; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await categoryService.EditCategory(inputModel); }); }
public async Task <IActionResult> Edit(CategoryEditInputModel categoryEditInputModel) { if (!this.ModelState.IsValid) { return(this.View(categoryEditInputModel)); } var categoryServiceModel = categoryEditInputModel.To <CategoryServiceModel>(); if (!await this.categoryService.EditAsync(categoryServiceModel)) { this.TempData["Error"] = EditErrorMessage; return(this.View()); } return(this.Redirect($"/Categories/Recipes/{categoryServiceModel.Id}")); }
public IActionResult Edit(int id) { CategoryEditInputModel editInputModel = this.categoryService .GetCategoryById(id) .To <CategoryEditInputModel>(); if (editInputModel == null) { // TODO: Error Handling return(this.Redirect("/")); } this.ViewData["mainCategories"] = this.mainCategoryService .GetAllMainCategories() .To <CreateCategoryMainCategoryViewModel>(); return(this.View(editInputModel)); }
public async Task EditCategory_ReturnsFalse_IfNameIsNotUnique() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoryService = new CategoryService(categoryRepository); var categoryTestSeeder = new CategoryTestSeeder(); await categoryTestSeeder.SeedCategories(context); var inputModel = new CategoryEditInputModel() { Id = "1", Name = "TestCategory", }; var result = await categoryService.EditCategory(inputModel); Assert.False(result); }
public async Task<bool> EditCategory(CategoryEditInputModel categoryEditInputModel) { var category = this.categoryRepository.All().SingleOrDefault(x => x.Id == categoryEditInputModel.Id); if (category == null) { throw new ArgumentNullException($"Cannot find a category with id {categoryEditInputModel.Id}"); } if (await this.CategoryNameIsNotUnique(categoryEditInputModel.Name)) { return false; } category.Name = categoryEditInputModel.Name; await this.categoryRepository.SaveChangesAsync(); return true; }
public IActionResult Edit(string id) { try { var categoryModel = this._categoryRepository.Get(id); var categoryEditModel = new CategoryEditInputModel { Id = categoryModel.Id, Name = categoryModel.Name, CoverUrl = categoryModel.CoverUrl }; return(this.View(categoryEditModel)); } catch (ArgumentException) { return(this.NotFound()); } }
public async Task EditCategory_ReturnsTrueAndEdits_WhenIModelIsValid() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoryService = new CategoryService(categoryRepository); var categoryTestSeeder = new CategoryTestSeeder(); await categoryTestSeeder.SeedCategories(context); var inputModel = new CategoryEditInputModel() { Id = "1", Name = "Changed", }; var booleanResult = await categoryService.EditCategory(inputModel); var category = await categoryRepository.All().SingleOrDefaultAsync(x => x.Id == "1"); Assert.True(booleanResult); Assert.Equal("Changed", category.Name); }
public async Task <IActionResult> Edit(CategoryEditInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } try { await this._categoryRepository.Edit(inputModel); this.TempData.AddSerialized <Alert>("Alerts", new Alert(AlertType.Success, "Successfully edited category.")); return(this.RedirectToAction(nameof(this.All))); } catch (ArgumentException e) { this.ModelState.AddModelError(string.Empty, e.Message); return(this.View(inputModel)); } }
public IActionResult Edit(CategoryEditInputModel model) { if (!this.categoryService.IsExist(model.Id)) { return(BadRequest()); } if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } var categoryServiceModel = new EditCategoryServiceModel { Id = model.Id, Name = model.Name, Decription = model.Decription }; this.categoryService.Edit(categoryServiceModel); return(RedirectToAction("All", "Categories")); }
public Task <int> EditAsync(CategoryEditInputModel input, string userId) { throw new NotImplementedException(); }