public async Task GetEditModelAsync_WithSubcategoryId_ShouldReturnValidServiceModel() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); IManagerSubcategoryService managerSubcategoryService = new ManagerSubcategoryService(database); // Act SubcategoryBasicServiceModel result = await managerSubcategoryService.GetEditModelAsync(firstNotDeletedSubcategoryId); // Assert result.Id.Should().Be(firstNotDeletedSubcategoryId); result.Name.Should().Be(firstNotDeletedSubcategoryName); }
public async Task <IActionResult> Edit(int id) { bool isSubcategoryExistingById = await this.subcategoryService.IsSubcategoryExistingById(id, false); if (!isSubcategoryExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, SubcategoryEntity)); return(this.RedirectToSubcategoriesIndex(false)); } SubcategoryBasicServiceModel subcategory = await this.managerSubcategoryService.GetEditModelAsync(id); SubcategoryFormViewModel model = new SubcategoryFormViewModel { Name = subcategory.Name, CategoryId = await this.subcategoryService.GetCategoryIdBySubcategoryId(id), Categories = await this.GetCategoriesSelectListItems() }; return(View(model)); }