예제 #1
0
        public async Task <IActionResult> AddClient([FromBody] ClientToBeAdded clientToAdd)
        {
            var createClient = _mapper.Map <Client>(clientToAdd);

            var result = await _clientRepo.AddClientAsync(createClient);

            if (result != null)
            {
                return(CreatedAtRoute("getclient", new { controller = "client", clientId = result.Id }, result));
            }

            return(BadRequest(new ApiResponse(400, "Something went wrong while adding the client")));
        }
예제 #2
0
        public async Task <IActionResult> UpdateClient(int id, [FromBody] ClientToBeAdded client)
        {
            // Re-using the same DTO for speed purposes
            // Retrieve client
            var clientFromRepo = await _clientRepo.GetClientByIdAsync(id);

            // Map client with Dto
            _mapper.Map(client, clientFromRepo);

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

            return(BadRequest(new ApiResponse(400, "Something went wrong while updating the client")));
        }