public async Task Handle(CustomerStatusChangeDomainEvent notification, CancellationToken cancellationToken)
        {
            _validator.Value
            .NotInvalidID(() => notification.CustomerId)
            .NotNullOrEmpty(() => notification.CustomerStatusCode)
            .Validate();

            IRepository <Domain.Entity.Customer> repository = _abstractRepositoryFactory.Value.Create(FructoseRepository)
                                                              .Create <Domain.Entity.Customer>();

            Domain.Entity.Customer customer = repository.Query()
                                              .SingleOrDefault(c => c.Id == notification.CustomerId);

            if (customer == null)
            {
                throw new MicroserviceException(ErrorCode.NODA, $"Could not find a Customer with ID = ${notification.CustomerId}");
            }

            LookupData customerStatus = _lookupDataRepository.Value.GetAllCustomerStatuses()
                                        .SingleOrDefault(cs => String.Equals(cs.Code, notification.CustomerStatusCode, StringComparison.OrdinalIgnoreCase));

            if (customerStatus == null)
            {
                throw new MicroserviceException(ErrorCode.NODA, $"Could not find a Customer Status with Code = ${notification.CustomerStatusCode}");
            }

            customer.CustomerStatusId = customerStatus.Id;

            await _unitOfWork.Value.CommitAsync();
        }
Ejemplo n.º 2
0
        public async Task <Unit> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
        {
            _validator.Value
            .NotNull(() => request)
            .NotNull(() => request.Customer)
            .NotInvalidID(() => request.Customer.ID)
            .Validate();

            IRepository <Domain.Entity.Customer> repository = _abstractRepositoryFactory.Value.Create(FructoseRepository)
                                                              .Create <Domain.Entity.Customer>();

            Domain.Entity.Customer customer = repository.Query()
                                              .SingleOrDefault(c => c.Id == request.Customer.ID);

            if (customer == null)
            {
                throw new MicroserviceException(ErrorCode.NODA, $"Could not find a Customer with ID = ${request.Customer.ID}");
            }

            _mapper.Value.MapOver(request.Customer, customer);

            await _unitOfWork.Value.CommitAsync();

            return(Unit.Value);
        }
        public static CustomerList CustomerTranslate(DataTypes.Customer[] customers)
        {
            CustomerList list = new CustomerList();

            Domain.Entity.Customer customer;

            for (int i = 0; i < customers.Length; i++)
            {
                customer             = new Domain.Entity.Customer();
                customer.CustomerId  = customers[i].CustomerId;
                customer.FirstName   = customers[i].FirstName;
                customer.LastName    = customers[i].LastName;
                customer.BirthDate   = customers[i].BirthDate;
                customer.MemberSince = customers[i].MemberSince;
                customer.IsModified  = customers[i].IsModified;
                customer.IsActive    = customers[i].IsActive;
                if (customers[i] != null)
                {
                    customer.Addresses = DataTypeToBusinessEntity.AddressTranslate(customers[i].Addresses);
                }
                if (customers[i] != null)
                {
                    customer.BillingMethods =
                        DataTypeToBusinessEntity.BillingMethodTranslate(customers[i].BillingMethods);
                }

                list.Add(customer);
            }

            return(list);
        }
Ejemplo n.º 4
0
 public Customer CustomerEntityToModel(Domain.Entity.Customer customerEntity)
 {
     return(new Customer()
     {
         City = customerEntity.City.Name,
         Classification = customerEntity.Classification.Name,
         Gender = customerEntity.Gender.Name,
         LastPurchase = customerEntity.LastPurchase.ToString("dd/MM/yyyy"),
         Name = customerEntity.Name,
         Phone = customerEntity.Phone,
         Region = customerEntity.Region.Name,
         Seller = customerEntity.User.Login
     });
 }
Ejemplo n.º 5
0
        public async Task <CustomerDTO> Handle(GetCustomerByIDCommand request, CancellationToken cancellationToken)
        {
            _validator.Value
            .NotNull(() => request)
            .NotInvalidID(() => request.ID)
            .Validate();

            IRepository <Domain.Entity.Customer> repository = _abstractRepositoryFactory.Value.Create(FructoseRepository)
                                                              .Create <Domain.Entity.Customer>();

            Domain.Entity.Customer customer = repository.Query()
                                              .SingleOrDefault(c => c.Id == request.ID);

            CustomerDTO customerDTO = _mapper.Value.MapTo <CustomerDTO>(customer);

            return(customerDTO);
        }
        public async Task <long> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            _validator.Value
            .NotNull(() => request)
            .NotNull(() => request.Customer)
            .Validate();

            Domain.Entity.Customer customer = _mapper.Value.MapTo <Domain.Entity.Customer>(request.Customer);

            IRepository <Domain.Entity.Customer> repository = _abstractRepositoryFactory.Value.Create(FructoseRepository)
                                                              .Create <Domain.Entity.Customer>();

            repository.Add(customer);

            await _unitOfWork.Value.CommitAsync();

            return(customer.Id);
        }