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));
        }
示例#2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                await _categoryService.CreateCategoryAsync(Category);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(RedirectToPage("./Categories"));
        }