public async Task <IActionResult> CreateProgramCategory(ProgramCategoryAdminCreateViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.categoriesService.CreateProgramCategoryAsync(inputModel); return(this.RedirectToAction("Index", "Home")); }
public async Task CreateProgramCategoryAsync(ProgramCategoryAdminCreateViewModel inputModel) { var programCategory = new ProgramCategory { Name = inputModel.Name, Description = inputModel.Description, }; await this.dbContext.ProgramCategories.AddAsync(programCategory); await this.dbContext.SaveChangesAsync(); }
public async Task CreateProgramCategoryAsyncShouldCreateBlogCategorySuccessfully() { 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 ProgramCategoryAdminCreateViewModel { Name = CategoryName, Description = CategoryDescription, }; await categoriesService.CreateProgramCategoryAsync(categoryInputModel); var actual = dbContext.ProgramCategories.FirstOrDefaultAsync(bc => bc.Name == CategoryName); Assert.Equal(actual.Result.Name, CategoryName); }