public async Task <ActionResult <Category> > PostCategory(Category category) { try { await _categoryService.CreateCategoryAsync(category); } catch (ArgumentNullException ex) { return(BadRequest(ex.Message)); } return(CreatedAtAction("GetCategory", new { id = category.Id }, category)); }
public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } try { await _categoryService.CreateCategoryAsync(Category); } catch (Exception ex) { return(BadRequest(ex)); } return(RedirectToPage("./Categories")); }