Пример #1
0
        public async Task <ClientResponse> SaveOrUpdateClientAsync(ClientRequest client)
        {
            Client clientEntity = new Client()
            {
                ClientId             = client.ClientId,
                FirstName            = client.FirstName,
                LastName             = client.LastName,
                CreationDate         = DateTime.Today,
                LastModificationDate = DateTime.Today,
                Active = true
            };

            if (clientEntity.ClientId > 0)
            {
                _dbContext.Clients.Update(clientEntity);
            }
            else
            {
                await _dbContext.Clients.AddAsync(clientEntity);
            }

            await _dbContext.SaveChangesAsync();

            return(new ClientResponse()
            {
                ClientId = clientEntity.ClientId,
                FirstName = clientEntity.FirstName,
                LastName = clientEntity.LastName
            });
        }
Пример #2
0
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            await _context.Set <TEntity>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task Handle(CreateClient command, CancellationToken cancellationToken = default(CancellationToken))
        {
            await Clients.AddAsync(new Client(
                                       command.Id.Value,
                                       command.Data.Name,
                                       command.Data.Email
                                       ));

            await dbContext.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(new ClientCreated(command.Id.Value, command.Data));
        }
Пример #4
0
        public async Task Handle(CreateClient command)
        {
            var id = command.Id ?? Guid.NewGuid();

            await Clients.AddAsync(new Client(
                                       id,
                                       command.Data.Name,
                                       command.Data.Email
                                       ));

            await dbContext.SaveChangesAsync();

            await eventBus.Publish(new ClientCreated(id, command.Data));
        }
        public async Task Create([FromBody]
                                 CreateClientInput input)
        {
            var entity = _mapper.Map <Client>(input);
            await _clientsDbContext.Clients.AddAsync(entity);

            await _clientsDbContext.SaveChangesAsync();
        }
Пример #6
0
        public async Task <AddressResponse> SaveAddressAsync(AddressRequest address)
        {
            Address addressEntity = new Address()
            {
                AddressId    = address.AddressId,
                City         = address.City,
                Country      = address.Country,
                PostalCode   = address.PostalCode,
                ClientId     = address.ClientId,
                CreationDate = DateTime.Today,
            };

            await _dbContext.AddAsync(addressEntity);

            await _dbContext.SaveChangesAsync();

            return(new AddressResponse()
            {
                AddressId = addressEntity.AddressId,
                City = addressEntity.City,
                Country = addressEntity.Country,
                PostalCode = addressEntity.PostalCode
            });
        }
        private async Task SaveAndPublish(Client client, CancellationToken cancellationToken = default)
        {
            await dbContext.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(client.DequeueUncommittedEvents().ToArray());
        }
        private async Task SaveAndPublish(Client client, CancellationToken cancellationToken = default(CancellationToken))
        {
            await dbContext.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(client.PendingEvents.ToArray());
        }