public Domain.Aggregate.Customer Insert(Domain.Aggregate.Customer costumer)
 {
     return(this.customerDBContext
            .Customers
            .Add(costumer)
            .Entity);
 }
        public async Task <bool> Handle(AddCustomerAddressCommand request, CancellationToken cancellationToken)
        {
            Address address = this.customerRepository.SelectAddressById(request.AddressId);

            Domain.Aggregate.Customer customer = this.customerRepository.SelectByCustomerIdentity(request.CustomerIdentity);
            customer.SetAddress(address);

            this.customerRepository.Update(customer);
            this.customerRepository.Update(address);
            bool result = await this.customerRepository.UnitOfWork.SaveEntitiesAsync();

            return(result);
        }
        public async Task <ActionResult> CreateCostumer(AddCustomerCommand addCostumerCommand)
        {
            try
            {
                Domain.Aggregate.Customer costumer = await this.mediator.Send(addCostumerCommand);

                return(this.Ok(costumer));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public async Task <ActionResult <Domain.Aggregate.Customer> > GetCustomerByIdentity(int identity)
        {
            try
            {
                Domain.Aggregate.Customer customer = await this.customerQueries.GetCostumerByIdentityAsync(identity);

                return(Ok(customer));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public async Task <ActionResult> UpdateCostumer(int identity, UpdateCustomerCommand updateCostumerCommand)
        {
            try
            {
                updateCostumerCommand.SetIdentity(identity);
                Domain.Aggregate.Customer costumer = await this.mediator.Send(updateCostumerCommand);

                return(this.Ok(costumer));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public void Test1()
        {
            Domain.Aggregate.Customer customer = Domain.Aggregate.Customer
                                                 .Create(1, "Caio", "Cesar", "Calisto", 'M');
            CustomerRepository.Insert(customer);
            Task saveTask = Task.Run(() => CustomerRepository.UnitOfWork.SaveEntitiesAsync());

            saveTask.Wait();

            Domain.Aggregate.Customer result = DbContext.Customers
                                               .Where(c => c.Name == "Caio" &&
                                                      c.MiddleName == "Cesar" &&
                                                      c.LastName == "Calisto" &&
                                                      c.Gender == 'M')
                                               .FirstOrDefault();
            Assert.NotNull(result);
        }
 public Domain.Aggregate.Customer Update(Domain.Aggregate.Customer costumer)
 {
     return(this.customerDBContext
            .Update(costumer)
            .Entity);
 }