Exemple #1
0
        public Task <bool> CreateToken(TokenModel model)
        {
            if (!model.IsValid())
            {
                return(Task.FromResult(false));
            }

            if (!_appRepository.Any(x => x.Id == model.AppId))
            {
                return(Task.FromResult(false));
            }

            var entity = new Token
            {
                CreatedBy   = model.CreatedBy,
                AppId       = model.AppId,
                Key         = model.Token,
                UsageCount  = 0,
                IsAppActive = true
            };

            _tokenRepository.Create(entity);
            _tokenRepository.SaveChanges();

            if (!_tokenRepository.SaveChanges())
            {
                Task.FromResult(true);
            }

            return(Task.FromResult(true));
        }
Exemple #2
0
        public Task <bool> CreateToken(TokenModel model)
        {
            if (!model.IsValid())
            {
                return(Task.FromResult(false));
            }

            var app = Context.Set <App>().FirstOrDefault(x => x.Id == model.AppId && x.UserId == model.CreatedBy);

            if (app == null)
            {
                return(Task.FromResult(false));
            }

            var user = Context.Set <User>().FirstOrDefault(x => x.Id == model.CreatedBy);

            if (user == null)
            {
                return(Task.FromResult(false));
            }

            if (user.RoleName == ConstHelper.User)
            {
                return(Task.FromResult(false));
            }

            var entity = new Token
            {
                CreatedBy   = user.Id,
                AppId       = app.Id,
                Id          = model.Token,
                UsageCount  = 0,
                IsAppActive = true,
                IsActive    = true
            };

            Context.Set <Token>().Add(entity);

            return(Task.FromResult(Context.SaveChanges() > 0));
        }