Exemplo n.º 1
0
        public void Execute(AuthorDto request)
        {
            _validator.ValidateAndThrow(request);
            var author = _context.Authors.Find(request.Id);

            _mapper.Map(request, author);
            _context.SaveChanges();
        }
        public void Execute(UpdateAuthorDto request)
        {
            _validator.ValidateAndThrow(request);
            var author = _context.Authors.Find(request.Id);

            if (author == null)
            {
                throw new EntityNotFOundException(request.Id, typeof(Author));
            }
            if (request.FirstName == null && request.LastName == null)
            {
                request.FirstName = author.FirstName;
                request.LastName  = author.LastName;
            }

            if (request.FirstName == null && request.LastName != null)
            {
                request.FirstName = author.FirstName;
            }

            if (request.FirstName != null && request.LastName == null)
            {
                request.LastName = author.LastName;
            }
            var birthPlace = author.BirthPlace;
            var birth      = author.Birth;

            author.FirstName  = request.FirstName;
            author.LastName   = request.LastName;
            author.BirthPlace = request.BirthPlace ?? birthPlace;
            author.Birth      = request.Birth ?? birth;

            //var birthPlace = actor.BirthPlace;


            // actor.BirthPlace = request.BirthPlace ?? birthPlace;

            _context.SaveChanges();
        }