コード例 #1
0
        public void Execute(UpdateGenreDto request)
        {
            var genre = context.Genres.Find(request.Id);

            if (genre == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Domain.Genre));
            }

            genre.Name = request.Name;

            context.SaveChanges();
        }
コード例 #2
0
        public ActionResult PutGenre(int id, UpdateGenreDto updateGenreDto)
        {
            Genre genre = _repo.GetGenreById(id);

            if (genre == null)
            {
                return(NotFound());
            }

            _mapper.Map(updateGenreDto, genre);
            _repo.UpdateGenre(genre);
            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #3
0
        public ActionResult PatchMovie(JsonPatchDocument <UpdateGenreDto> jsonDoc, int id)
        {
            Genre genre = _repo.GetGenreById(id);

            if (genre == null)
            {
                return(NotFound());
            }
            UpdateGenreDto genreToPatch = _mapper.Map <UpdateGenreDto>(genre);

            jsonDoc.ApplyTo(genreToPatch);

            if (!TryValidateModel(genreToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(genreToPatch, genre);
            _repo.UpdateGenre(genre);
            _repo.SaveChanges();
            return(NoContent());
        }
コード例 #4
0
 public IActionResult Put(int id, [FromBody] UpdateGenreDto dto, [FromServices] IUpdateGenreCommand command)
 {
     dto.Id = id;
     executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }