示例#1
0
        public async Task <Result <TEntity> > CreateAsync(TEntity model)
        {
            try
            {
                _context.Add(model);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(Result.Create(model, ex.InnerException?.Message, 500));
            }

            return(Result.Create(model));
        }
示例#2
0
        public async Task <Result <User> > CheckUserNamePasswordAsync(string userName, string password)
        {
            try
            {
                var user = await _context.User.FirstOrDefaultAsync(x => x.UserName == userName);

                if (user != null)
                {
                    var passwordCheck = user.Password == Encryption.GenerateHash(password, _configuration["Salt"]);
                    if (passwordCheck)
                    {
                        user.FailedCount = 0;
                        return(Result.Create(user));
                    }
                    user.FailedCount++;
                    await _context.SaveChangesAsync();

                    return(Result.Create(default(User), "UserName or password is incorrect!", 500));
                }
                return(Result.Create(default(User), "UserName not found!", 500));
            }
            catch (Exception ex)
            {
            }
            return(Result.Create(default(User), "An error occurred!", 500));
        }