コード例 #1
0
        public async Task <IHttpActionResult> PutAsync(string genreName, [FromBody] GenreCompleteModelIn newGenre)
        {
            await Task.Yield();

            if (genreName == "" || newGenre == null)
            {
                return(BadRequest("Genre name can not be empty"));
            }
            try
            {
                genreService.Update(genreName, newGenre.ToEntity());
                return(Ok(newGenre));
            }
            catch (DataBaseException)
            {
                return(Content(HttpStatusCode.NotFound, $"{genreName} does not exist in our database"));
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> PostAsync([FromBody] GenreCompleteModelIn newGenre)
        {
            await Task.Yield();

            if (newGenre == null)
            {
                return(BadRequest("Genre can not be empty"));
            }
            try
            {
                genreService.Upload(newGenre.ToEntity());
                return(Content(HttpStatusCode.Created, $"{newGenre.Name} created"));
            }
            catch (DataBaseException)
            {
                return(Content(HttpStatusCode.Accepted, $"{newGenre.Name} already exists"));
            }
        }