Exemplo n.º 1
0
        public virtual async Task <CustomerDto> SendVerificationCodeAgain(RegisterCustomerArgs args, CancellationToken cancellationToken)
        {
            if (!CustomerValidator.IsValid(args.customer, out string errorMessage))
            {
                throw new DomainLogicException(errorMessage);
            }

            Customer customer = DtoEntityMapper.FromDtoToEntity(args.customer);

            customer = await(await CustomersRepository.GetAllAsync(cancellationToken))
                       .Where(cu => cu.NationalCode == customer.NationalCode || cu.Mobile == customer.Mobile)
                       .FirstOrDefaultAsync(cancellationToken);

            customer.VerifyCode = await SmsService.SendVerifyCode(customer.Mobile);

            return(DtoEntityMapper.FromEntityToDto(await CustomersRepository.UpdateAsync(customer, cancellationToken)));
        }
Exemplo n.º 2
0
        public virtual async Task <CustomerDto> RegisterCustomer(RegisterCustomerArgs args, CancellationToken cancellationToken)
        {
            if (!CustomerValidator.IsValid(args.customer, out string errorMessage))
            {
                throw new DomainLogicException(errorMessage);
            }

            Customer customer = DtoEntityMapper.FromDtoToEntity(args.customer);

            bool existingCustomer = await(await CustomersRepository.GetAllAsync(cancellationToken))
                                    .Where(cu => cu.NationalCode == customer.NationalCode || cu.Mobile == customer.Mobile)
                                    .AnyAsync(cancellationToken);

            if (existingCustomer)
            {
                throw new DomainLogicException("CustomerIsAlreadyRegistered");
            }
            else
            {
                customer.VerifyCode = await SmsService.SendVerifyCode(customer.Mobile);

                return(DtoEntityMapper.FromEntityToDto(await CustomersRepository.AddAsync(customer, cancellationToken)));
            }
        }