public ResponseObject <ClientForGetDto> Update(ClientForUpdateDto clientForUpdateDto)
        {
            if (!ValidateCPF.IsCpf(clientForUpdateDto.SocialSecurityNumber))
            {
                return(new ResponseObject <ClientForGetDto>(false, "CPF Inválido"));
            }

            var occupationForCheckId = _occupationRepository.GetById(clientForUpdateDto.IdOccupation);

            if (occupationForCheckId == null)
            {
                return(new ResponseObject <ClientForGetDto>(false, "Não existe um cargo com o ID informado"));
            }

            var clientForCheckId = _clientRepository.GetById(clientForUpdateDto.Id);

            if (clientForCheckId == null)
            {
                return(new ResponseObject <ClientForGetDto>(false, "Não existe um usuário com o ID informado"));
            }

            var clientForUpdate = _mapper.Map <Client>(clientForUpdateDto);

            _clientRepository.Update(clientForUpdate);
            var commit = _unityOfWork.Commit();

            return(commit
                ? new ResponseObject <ClientForGetDto>(true, obj: _mapper.Map <ClientForGetDto>(clientForUpdate))
                : new ResponseObject <ClientForGetDto>(false));
        }
        public IActionResult UpdateClient(Guid clientId, [FromBody] ClientForUpdateDto clientDto)
        {
            if (clientDto == null)
            {
                return(BadRequest());
            }

            var clientFromRepo = _repository.GetClient(clientId);

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

            Mapper.Map(clientDto, clientFromRepo);

            _repository.UpdateClient(clientFromRepo);

            if (!_repository.Save())
            {
                return(StatusCode(500));
            }

            return(NoContent());
        }
        public void Update_Client()
        {
            var controller      = new ClientsController(new ClientRepositoryMock(), new HRServiceMock());
            var clientForUpdate = new ClientForUpdateDto()
            {
                FirstName = "Steven",
                LastName  = "Hoe",
                Email     = "*****@*****.**"
            };

            var result   = controller.Put(ClientRepositoryMock.TestClient.Id, clientForUpdate);
            var okResult = result.Should().BeOfType <NoContentResult>().Subject;
        }
        public IActionResult Update([FromBody] ClientForUpdateDto clientForUpdateDto)
        {
            var result = _clientService.Update(clientForUpdateDto);

            if (result.Success)
            {
                return(Ok(result.Object));
            }

            if (!string.IsNullOrEmpty(result.Message))
            {
                return(BadRequest(new { error = result.Message }));
            }

            return(StatusCode(500));
        }
Beispiel #5
0
        public IActionResult Updateclient(Guid clientId, ClientForUpdateDto client)
        {
            var clientFromRepo = _carRentalRepository.GetClient(clientId);

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

            _mapper.Map(client, clientFromRepo);

            _carRentalRepository.UpdateClient(clientFromRepo);
            _carRentalRepository.Save();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateClient(int id, [FromBody] ClientForUpdateDto clientForUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(clientForUpdateDto, userFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("$Updating client {id} failed on save");
        }
        public IActionResult Put(int id, [FromBody] ClientForUpdateDto client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var clientFetched = _clientRepository.GetClient(id, false);

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

            _mapper.Map(client, clientFetched);
            _clientRepository.Save();

            return(NoContent());
        }
Beispiel #8
0
        public IActionResult Put(int id, [FromBody] ClientForUpdateDto clientForUpdate)
        {
            var client = _clientRepository.Get(id);

            if (client == null)
            {
                return(NotFound("Client not found"));
            }

            client.FirstName = clientForUpdate.FirstName != null ? clientForUpdate.FirstName : client.FirstName;
            client.LastName  = clientForUpdate.LastName != null ? clientForUpdate.LastName : client.LastName;
            client.Email     = clientForUpdate.Email != null ? clientForUpdate.Email : client.Email;

            _clientRepository.Update(client);
            if (!_clientRepository.Save())
            {
                return(BadRequest("Could not update client"));
            }

            return(NoContent());
        }