public async Task <IActionResult> CreateProductCategory(ProductCategoryAdminCreateViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.categoriesService.CreateProductCategoryAsync(inputModel); return(this.RedirectToAction("Index", "Home")); }
public async Task CreateProductCategoryAsync(ProductCategoryAdminCreateViewModel inputModel) { var productCategory = new ProductCategory { Name = inputModel.Name, }; await this.dbContext.ProductCategories.AddAsync(productCategory); await this.dbContext.SaveChangesAsync(); }
public async Task CreateProductCategoryAsyncShouldCreateBlogCategorySuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var categoriesService = new CategoriesService(dbContext, null); var categoryInputModel = new ProductCategoryAdminCreateViewModel { Name = CategoryName, }; await categoriesService.CreateProductCategoryAsync(categoryInputModel); var actual = dbContext.ProductCategories.FirstOrDefaultAsync(bc => bc.Name == CategoryName); Assert.Equal(actual.Result.Name, CategoryName); }