public async Task <ProviderAccessTokenModel> CreateToken(string providerId, ProviderAccessTokenCreateModel model)
        {
            var provider = await _repositoryProvider.GetFirst(x => x.Id == providerId && x.State == MREntityState.Active);

            if (provider == null)
            {
                _eNotFound("Provider not found");
            }

            if (!provider.IsEditAllow(_userId) && !_userRoles.Contains(AppRoles.ADMINISTRATOR.ToString()))
            {
                _eAccessDenied(typeof(Provider));
            }

            var entity = _mapper.Map <ProviderToken>(model);

            entity.CreatedBy  = _userId;
            entity.CreateTime = DateTime.UtcNow;
            entity.Value      = KeyGenerator.GenerateAccessKey(16);

            await _repositoryProvider.UpdateAddToken(providerId, entity);

            var result = _mapper.Map <ProviderAccessTokenModel>(entity);

            result.CreatedById    = _userId;
            result.CreatedByEmail = _userEmail;

            return(result);
        }
        public async Task <bool> UpdateEmail(UserUpdateEmailModel model)
        {
            var exists = await _repositoryUser.Any(x => x.Email == model.Email && x.State == MREntityState.Active);

            if (exists)
            {
                throw new MRException <object>((int)ExceptionCode.SYSTEM_EXCEPTION, "Email already in use");
            }

            var currentUser = await _repositoryUser.Get(_userId);

            if (!await _managerUser.CheckPasswordAsync(currentUser, model.Password))
            {
                throw new MRException <object>((int)ExceptionCode.ACCESS_DENIED, "Wrong password");
            }

            var entity = new EmailChangeUnit
            {
                NewEmail = model.Email,
                OldEmail = _userEmail,
                Status   = Infrastructure.Entity.Enum.EmailChangeResult.NEW,
                Expired  = DateTime.UtcNow.AddDays(3),
                Token    = KeyGenerator.GenerateAccessKey(8),
                UserId   = _userId,
            };

            await _repositoryEmailChangeUnit.Insert(entity);

            return(true);
        }