public async Task <ActionResult <ClientModel> > GetById(long id) { _logger.LogDebug($"Getting a client with id {id}"); var client = await _dbContext.Clients.FindAsync(id); if (client == null) { return(NotFound()); } return(ClientModel.FromClient(client)); }
public async Task <ActionResult <ClientModel> > Create(ClientInputModel model) { _logger.LogDebug($"Creating a new client with name {model.Name}"); var client = new Client(); model.MapTo(client); await _dbContext.Clients.AddAsync(client); await _dbContext.SaveChangesAsync(); var resultModel = ClientModel.FromClient(client); return(CreatedAtAction(nameof(GetById), "clients", new { id = client.Id }, resultModel)); }
public async Task <ActionResult <ClientModel> > Update(long id, ClientInputModel model) { _logger.LogDebug($"Updating client with id {id}"); var client = await _dbContext.Clients.FindAsync(id); if (client == null) { return(NotFound()); } model.MapTo(client); _dbContext.Clients.Update(client); await _dbContext.SaveChangesAsync(); return(ClientModel.FromClient(client)); }