public void Update()
        {
            var accountProfile = new AccountProfileUpdateSchema {
                Id       = 1,
                StatusId = Status.Active.ToInt()
            };

            _accountProfileService.UpdateAsync(accountProfile).GetAwaiter().GetResult();
            Assert.IsTrue(accountProfile.StatusCode == 200);
        }
Exemple #2
0
 public async Task UpdateAsync(AccountProfileUpdateSchema accountProfile)
 {
     await _storedProcedure.ExecuteAsync(accountProfile);
 }
        public async Task <ActionResult> ActivateAccountAsync([FromBody] ActivateAccountBindingModel collection)
        {
            if (collection == null ||
                string.IsNullOrWhiteSpace(collection.Username) ||
                string.IsNullOrWhiteSpace(collection.Code))
            {
                return(BadRequest(_localizer[DataTransferer.DefectiveEntry().Message]));
            }

            var query = new AccountProfileGetFirstSchema {
                LinkedId = collection.Username
            };

            if (collection.Username.IsPhoneNumber())
            {
                query.TypeId = AccountProfileType.Phone.ToInt();
            }
            else if (new EmailAddressAttribute().IsValid(collection.Username))
            {
                query.TypeId = AccountProfileType.Email.ToInt();
            }
            else
            {
                return(BadRequest(_localizer[DataTransferer.InvalidEmailOrCellPhone().Message]));
            }

            try {
                var accountProfile = await _accountProfileService.FirstAsync(query).ConfigureAwait(true);

                if (accountProfile == null)
                {
                    if (query.TypeId == AccountProfileType.Phone.ToInt())
                    {
                        return(BadRequest(_localizer[DataTransferer.PhoneNotFound().Message]));
                    }

                    if (query.TypeId == AccountProfileType.Email.ToInt())
                    {
                        return(BadRequest(_localizer[DataTransferer.EmailNotFound().Message]));
                    }
                }

                var activationCode = _memoryCache.Get(collection.Username);
                if (activationCode == null)
                {
                    return(BadRequest(_localizer[DataTransferer.ActivationCodeRequestedNotFound().Message]));
                }

                if (collection.Code != activationCode.ToString())
                {
                    return(BadRequest(_localizer[DataTransferer.ActivationCodeRequestedNotFound().Message]));
                }

                _memoryCache.Remove(collection.Username);
                var accountProfileQuery = new AccountProfileUpdateSchema {
                    Id       = accountProfile.Id.Value,
                    StatusId = Status.Active.ToInt()
                };
                await _accountProfileService.UpdateAsync(accountProfileQuery).ConfigureAwait(true);

                return(Ok(_localizer[DataTransferer.AccountActivated().Message]));
            }
            catch (Exception ex) {
                Log.Error(ex, ex.Source);
                return(Problem());
            }
        }