public async Task <int> Create(ClientDto client) { var clientEntity = new Client(); client.UpdateClient(clientEntity); await _context.Clients.AddAsync(clientEntity); await _context.SaveChangesAsync(); return(clientEntity.Id); }
public async Task Update(ClientDto clientDto) { var client = await _context.Clients.FirstOrDefaultAsync(c => c.Id == clientDto.Id); if (client != null) { clientDto.UpdateClient(client); await _context.SaveChangesAsync(); } else { throw new NotFoundException(); } }
public async Task <ClientDto> Update(int id, [FromBody] ClientDto clientDto) { // Tässä esimerkissä businessId on vakio, seuraavassa esimerkissä se // haetaan käyttäjän tiedoista var businessId = 1; var client = await clientService.GetByBusiness(businessId, clientDto.Id); // Päivitä laskua dtosta clientDto.UpdateClient(client); await clientService.Update(client); // Palauta päivitetty lasku return(ClientDto.FromClient(client)); }
public async Task <ClientDto> Update(int id, [FromBody] ClientDto clientDto, [RequestBusiness] Business business) { if (!await clientsAuthorize.CanUpdateClient(User, id, clientDto)) { throw new Forbidden(); } var client = await clientService.GetByBusiness(business.Id, id); // Päivitä laskua dtosta clientDto.UpdateClient(client); await clientService.Update(client); // Palauta päivitetty lasku return(ClientDto.FromClient(client)); }