Пример #1
0
        protected Customer GetCustomer(CreateCustomerRequest request)
        {
            var firstName = request.FirstName;
            var lastName  = request.LastName;

            return(_customerFactory.Create(firstName, lastName));
        }
        private void CreateCustomer(CustomerModel model)
        {
            Customer customer = _factory.Create(model);

            _context.Customers.Add(customer);

            _context.Save();
        }
        public void Execute(CreateCustomerModel model)
        {
            var _customer   = _repositories.GetCustomer(model.CustomerId);
            var _cityCounty = _repositories.GetCityCounty(model.CityCountyId);
            var customer    = _factory.Create(_customer, _cityCounty);

            _repositories.AddCustomer(customer);
            _unitOfWork.Save();
        }
        public Customer Execute(CreateCustomerModel model)
        {
            var customer = _factory.Create(model.FirstName, model.LastName);

            _database.Customers.Add(customer);

            _database.Save();

            return customer;
        }
Пример #5
0
        protected async Task <List <Customer> > CreateSomeCustomersAsync()
        {
            var customers = new List <Customer>();

            for (var i = 0; i < 10; i++)
            {
                var customer = _customerFactory.Create($"John{i}", $"Smith{i}");
                await _customerRepository.AddAsync(customer);

                customers.Add(customer);
            }

            return(customers);
        }
Пример #6
0
        public Customer Add(Customer item)
        {
            try
            {
                var customer = _mapper.Map <CustomerDTO>(item);
                var result   = _factory.Create(customer);
                return(result);
            }
            catch (Exception e)
            {
                _logger.LogError($"There is a problem with save Customer : {e}");
            }

            return(null);
        }
Пример #7
0
        public async Task <IResult <long> > AddAsync(CustomerModel model)
        {
            var validation = await new AddCustomerModelValidator().ValidationAsync(model);

            if (validation.Failed)
            {
                return(Result <long> .Fail(validation.Message));
            }

            var customer = _customerFactory.Create(model);

            await _customerRepository.AddAsync(customer);

            await _unitOfWork.SaveChangesAsync();

            return(Result <long> .Success(customer.Id));
        }
        public async Task CanAddNewCustomer()
        {
            // Arrange

            await CreateSomeCustomersAsync();

            var customer = _customerFactory.Create("John", "Smith");

            // Act

            await _customerRepository.AddAsync(customer);

            // Assert

            var retrievedCustomer = await _customerRepository.FindAsync(customer.Id);

            retrievedCustomer.Should().BeEquivalentTo(customer);
        }
Пример #9
0
        public Customer AddCustomer(CustomerDto customerDto)
        {
            if (customerDto == null)
            {
                throw new ArgumentNullException(nameof(customerDto));
            }

            var newCustomer = customerFactory.Create(customerDto.Name, customerDto.Email, customerDto.Avatar);

            if (newCustomer.Active == false)
            {
                newCustomer.Active = true;
                customerRepository.Modify(newCustomer);
            }
            else
            {
                customerRepository.Add(newCustomer);
            }

            customerRepository.UnitOfWork.Commit();

            return(newCustomer);
        }
Пример #10
0
        public async Task <Customer> ImportCustomerAsync(Customer customer)
        {
            bool success;
            var  importedCustomer = default(Customer);

            #region Validate
            var validationResult = await _customerIsValidToImportValidator.Validate(customer);

            if (validationResult.HasErrorMessage)
            {
                await SendDomainNotifications(validationResult);

                return(_customerFactory.Create(validationResult));
            }
            #endregion

            // Check if customer exists
            var getCustomerByCodeQuery = new GetCustomerByCodeQuery(UserSessionInfo, GlobalizationInfo, validationResult, customer.Code);
            _ = await InMemoryBus.SendQueryAsync(getCustomerByCodeQuery);

            var customerAlreadyExists = getCustomerByCodeQuery.QueryResult != null;
            if (!customerAlreadyExists)
            {
                #region Process
                importedCustomer = _customerFactory.Create(validationResult);
                try
                {
                    importedCustomer.ImportCustomer(
                        new TenantInfoValueObject(UserSessionInfo.TenantInfo.TenantCode),
                        _systemUserFactory.Create(UserSessionInfo),
                        customer.Code,
                        customer.Name,
                        customer.BirthDate
                        );

                    success = importedCustomer?.Id != Guid.Empty;
                }
                catch (Exception ex)
                {
                    _ = await InMemoryBus.SendRaisedExceptionEventAsync(UserSessionInfo, GlobalizationInfo, ex);

                    _ = await InMemoryBus.SendEventAsync(new CustomerImportFailedEvent(
                                                             UserSessionInfo,
                                                             GlobalizationInfo,
                                                             validationResult,
                                                             customer));

                    success = false;
                }
                #endregion

                #region Notify
                if (!customerAlreadyExists)
                {
                    if (success)
                    {
                        _ = await InMemoryBus.SendEventAsync(new CustomerWasImportedEvent(
                                                                 UserSessionInfo,
                                                                 GlobalizationInfo,
                                                                 validationResult,
                                                                 importedCustomer
                                                                 ));
                    }
                    else
                    {
                        _ = await InMemoryBus.SendEventAsync(new CustomerImportFailedEvent(
                                                                 UserSessionInfo,
                                                                 GlobalizationInfo,
                                                                 validationResult,
                                                                 importedCustomer
                                                                 ));
                    }
                }
                #endregion
            }

            return(importedCustomer);
        }