Пример #1
0
        public void Handle(UpdateBookingSettings command)
        {
            var account = _repository.Find(command.AccountId);

            var settings = new BookingSettings();

            Mapper.Map(command, settings);

            account.UpdateBookingSettings(settings, command.Email, command.DefaultTipPercent);

            _repository.Save(account, command.Id.ToString());
        }
Пример #2
0
        private static void EnsureDefaultAccountsHasCorrectSettings(ConnectionStringSettings connectionString, ICommandBus commandBus)
        {
            var accounts = new AccountDao(() => new BookingDbContext(connectionString.ConnectionString));
            var admin    = accounts.FindByEmail("*****@*****.**");

            if (admin != null &&
                (!admin.HasAdminAccess || !admin.IsConfirmed))
            {
                commandBus.Send(new UpdateRoleToUserAccount
                {
                    AccountId = admin.Id,
                    RoleName  = RoleName.SuperAdmin,
                });

                commandBus.Send(new ConfirmAccount
                {
                    AccountId        = admin.Id,
                    ConfimationToken = admin.ConfirmationToken
                });
            }

            var john = accounts.FindByEmail("*****@*****.**");

            if (john != null)
            {
                var updateAccountCommand = new UpdateBookingSettings
                {
                    AccountId         = john.Id,
                    Country           = new CountryISOCode("CA"),
                    Phone             = "6132875020",
                    Name              = "John Doe",
                    Email             = "*****@*****.**",
                    NumberOfTaxi      = john.Settings.NumberOfTaxi,
                    ChargeTypeId      = john.Settings.ChargeTypeId,
                    DefaultTipPercent = john.DefaultTipPercent
                };
                commandBus.Send(updateAccountCommand);
            }
        }
        public object Put(AccountUpdateRequest accountUpdateRequest)
        {
            Guid accountId = accountUpdateRequest.AccountId;
            var  request   = accountUpdateRequest.BookingSettingsRequest;

            AccountDetail existingEmailAccountDetail = _accountDao.FindByEmail(request.Email);
            AccountDetail currentAccountDetail       = _accountDao.FindById(accountId);

            if (currentAccountDetail.Email != request.Email && currentAccountDetail.FacebookId.HasValue())
            {
                throw new HttpError(HttpStatusCode.BadRequest, _resources.Get("EmailChangeWithFacebookAccountErrorMessage"));
            }

            if (existingEmailAccountDetail != null && existingEmailAccountDetail.Email == request.Email && existingEmailAccountDetail.Id != accountId)
            {
                throw new HttpError(HttpStatusCode.BadRequest, ErrorCode.EmailAlreadyUsed.ToString(), _resources.Get("EmailUsedMessage"));
            }

            CountryCode countryCode = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode(request.Country));

            if (PhoneHelper.IsPossibleNumber(countryCode, request.Phone))
            {
                request.Phone = PhoneHelper.GetDigitsFromPhoneNumber(request.Phone);
            }
            else
            {
                throw new HttpError(string.Format(_resources.Get("PhoneNumberFormat"), countryCode.GetPhoneExample()));
            }

            var isChargeAccountEnabled = _serverSettings.GetPaymentSettings().IsChargeAccountPaymentEnabled;

            // Validate account number if charge account is enabled and account number is set.
            if (isChargeAccountEnabled && !string.IsNullOrWhiteSpace(request.AccountNumber))
            {
                if (!request.CustomerNumber.HasValue())
                {
                    throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString());
                }

                // Validate locally that the account exists
                var account = _accountChargeDao.FindByAccountNumber(request.AccountNumber);
                if (account == null)
                {
                    throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString());
                }

                // Validate with IBS to make sure the account/customer is still active
                var ibsChargeAccount = _ibsServiceProvider.ChargeAccount().GetIbsAccount(request.AccountNumber, request.CustomerNumber);
                if (!ibsChargeAccount.IsValid())
                {
                    throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString());
                }
            }

            var command = new UpdateBookingSettings();

            Mapper.Map(request, command);

            command.AccountId = accountId;

            _commandBus.Send(command);

            return(new HttpResult(HttpStatusCode.OK));
        }
Пример #4
0
        public void Get(ConfirmationCodeRequest request)
        {
            var account = _accountDao.FindByEmail(request.Email);

            if (account == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "No account matching this email address");
            }

            if (!_serverSettings.ServerData.AccountActivationDisabled)
            {
                if (_serverSettings.ServerData.SMSConfirmationEnabled)
                {
                    var countryCodeForSMS = account.Settings.Country;
                    var phoneNumberForSMS = account.Settings.Phone;

                    CountryCode countryCodeFromRequest = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode(request.CountryCode));

                    if (countryCodeFromRequest.IsValid() &&
                        request.PhoneNumber.HasValue() &&
                        PhoneHelper.IsPossibleNumber(countryCodeFromRequest, request.PhoneNumber) &&
                        (account.Settings.Country.Code != countryCodeFromRequest.CountryISOCode.Code || account.Settings.Phone != request.PhoneNumber))
                    {
                        if (_blackListEntryService.GetAll().Any(e => e.PhoneNumber.Equals(request.PhoneNumber.ToSafeString())))
                        {
                            throw new HttpError(_resources.Get("PhoneBlackListed"));
                        }

                        countryCodeForSMS = countryCodeFromRequest.CountryISOCode;
                        phoneNumberForSMS = request.PhoneNumber;

                        var updateBookingSettings = new UpdateBookingSettings()
                        {
                            AccountId         = account.Id,
                            Email             = account.Email,
                            Name              = account.Name,
                            Country           = countryCodeFromRequest.CountryISOCode,
                            Phone             = request.PhoneNumber,
                            Passengers        = account.Settings.Passengers,
                            VehicleTypeId     = account.Settings.VehicleTypeId,
                            ChargeTypeId      = account.Settings.ChargeTypeId,
                            ProviderId        = account.Settings.ProviderId,
                            NumberOfTaxi      = account.Settings.NumberOfTaxi,
                            AccountNumber     = account.Settings.AccountNumber,
                            CustomerNumber    = account.Settings.CustomerNumber,
                            DefaultTipPercent = account.DefaultTipPercent,
                            PayBack           = account.Settings.PayBack
                        };

                        _commandBus.Send(updateBookingSettings);
                    }

                    _commandBus.Send(new SendAccountConfirmationSMS
                    {
                        ClientLanguageCode = account.Language,
                        Code        = account.ConfirmationToken,
                        CountryCode = countryCodeForSMS,
                        PhoneNumber = phoneNumberForSMS
                    });
                }
                else
                {
                    _commandBus.Send(new SendAccountConfirmationEmail
                    {
                        ClientLanguageCode = account.Language,
                        EmailAddress       = account.Email,
                        ConfirmationUrl    =
                            new Uri(string.Format("/api/account/confirm/{0}/{1}", account.Email,
                                                  account.ConfirmationToken), UriKind.Relative)
                    });
                }
            }
        }