Exemplo n.º 1
0
        public async Task <Client> CreateClientAsync(UpdateClientRequest client)
        {
            var dbClient = _mapper.Map <ClientDb>(client);

            _clCtx.Clients.Add(dbClient);

            await _clCtx.SaveChangesAsync();

            return(_mapper.Map <Client>(dbClient));
        }
Exemplo n.º 2
0
        public async Task <Client> UpdateClientByIdAsync(int clientId, UpdateClientRequest client)
        {
            var dbClients = await _clCtx.Clients.Where(c => c.ClientId == clientId).ToArrayAsync();

            if (dbClients[0] is null)
            {
                return(null);
            }

            var newClient = _mapper.Map <ClientDb>(client);
            var oldClient = dbClients[0];

            newClient.ClientId = oldClient.ClientId;
            newClient.Created  = oldClient.Created;
            newClient.Updated  = DateTime.UtcNow;

            await _clCtx.SaveChangesAsync();

            return(_mapper.Map <Client>(newClient));
        }