public async Task <IActionResult> Edit(SubforumFormViewModel model) { if (!ModelState.IsValid) { model.Categories = SetCategoriesList(await this.categories.AllAsync()); return(View(model)); } await this.subforums.EditAsync(model.Id, model.Name, model.SelectedCategory); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(int?categoryId) { var categories = await this.categories.AllAsync(); var categoriesList = SetCategoriesList(categories); var model = new SubforumFormViewModel { Categories = categoriesList }; if (categoryId != null) { model.CurrentCategoryId = (int)categoryId; } return(View(model)); }
public async Task <IActionResult> Edit(int id) { var subforum = await this.subforums.ByIdAsync(id); if (subforum == null) { return(BadRequest()); } var categories = await this.categories.AllAsync(); var categoriesList = SetCategoriesList(categories); var model = new SubforumFormViewModel { Id = id, Name = subforum.Name, Categories = categoriesList, CurrentCategoryId = subforum.CategoryId }; return(View(model)); }
public async Task <IActionResult> Create(SubforumFormViewModel model) { await this.subforums.CreateAsync(model.Name, model.SelectedCategory); return(RedirectToAction(nameof(Index))); }