/// <inheritdoc/> public async Task <Client> UpdateClientAsync(int clentId, UpdateClientRequest updateRequest) { var dbClients = await _context.Clients.Where(o => o.Address == updateRequest.Address && o.ClientId != clentId).ToArrayAsync(); if (dbClients.Length > 0) { throw new RequestedResourceHasConflictException("code"); } dbClients = await _context.Clients.Where(o => o.ClientId == clentId).ToArrayAsync(); var dbClient = dbClients.FirstOrDefault(); if (dbClients == null) { throw new RequestedResourceNotFoundException(); } Mapper.Map(updateRequest, dbClient); //dbOrder.LastUpdatedBy = _userContext.UserId; await _context.SaveChangesAsync(); return(Mapper.Map <Client>(dbClient)); }
/// <inheritdoc/> public async Task <Client> CreateClientAsync(UpdateClientRequest createRequest) { var dbClients = await _context.Clients.Where(h => h.FirstName == createRequest.FirstName).ToArrayAsync(); if (dbClients.Length > 0) { throw new RequestedResourceHasConflictException("Client"); } var dbClient = Mapper.Map <UpdateClientRequest, DbClient>(createRequest); _context.Clients.Add(dbClient); await _context.SaveChangesAsync(); return(Mapper.Map <Client>(dbClient)); }