コード例 #1
0
        public async Task <ActionResult <Genre> > PostGenre(Genre genre)
        {
            try
            {
                await _genreService.CreateGenreAsync(genre);
            }
            catch (ArgumentNullException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(CreatedAtAction("GetGenre", new { id = genre.Id }, genre));
        }
コード例 #2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                await _genreService.CreateGenreAsync(Genre);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

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