Exemple #1
0
 public IActionResult Update(UpdateActorDto actor)
 {
     try
     {
         _service.Update(actor);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(Ok());
 }
Exemple #2
0
        public void Execute(UpdateActorDto request)
        {
            _validator.ValidateAndThrow(request);

            var actor = _context.Actors.Find(request.Id);

            if (actor == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Actor));
            }


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

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

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

            var birthPlace = actor.BirthPlace;
            var oscars     = actor.Oscars;

            actor.LastName         = request.LastName;
            actor.FirstName        = request.FirstName;
            actor.FirstAndLastName = request.FullName;
            actor.Oscars           = request.Oscars ?? oscars;
            actor.BirthPlace       = request.BirthPlace ?? birthPlace;

            _context.SaveChanges();
        }
Exemple #3
0
        public async Task <IActionResult> UpdateActor(int id, [FromBody] UpdateActorDto actorDto)
        {
            try
            {
                if (id < 1 || actorDto == null || id != actorDto.Id)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var exists = await _actorRepo.Exists(id);

                if (!exists)
                {
                    return(NotFound());
                }

                var actorObj = _mapper.Map <Actor>(actorDto);
                var success  = await _actorRepo.Update(actorObj);

                if (!success)
                {
                    ModelState.AddModelError("", "Something went wrong when deleting the record");
                    return(StatusCode(500, ModelState));
                }

                return(NoContent());
            }

            catch (Exception e)
            {
                return(StatusCode(500, "Something went wrong. Please contact your admin"));
            }
        }
 public IActionResult Put(int id, [FromBody] UpdateActorDto dto, [FromServices] IUpdateActorCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(NoContent());
 }