示例#1
0
 public async Task CreateAccount(User user)
 {
     using (var context = new UserEntities())
     {
         context.Users.Add(user);
         await context.SaveChangesAsync();
     }
 }
示例#2
0
        public async Task <User> GetUserByUsername(string username)
        {
            User user;

            using (var context = new UserEntities())
            {
                user = await context.Users.FirstOrDefaultAsync(x => x.Username == username);
            }

            return(user);
        }
示例#3
0
        public async Task <User> GetUser(string userId)
        {
            User user;

            using (var context = new UserEntities())
            {
                int.TryParse(userId, out var id);
                user = await context.Users.FirstOrDefaultAsync(x => x.UserId == id);
            }

            return(user);
        }
示例#4
0
        public async Task <RequestResponse <bool> > IsUsernameValid(string username)
        {
            User user;

            using (var context = new UserEntities())
            {
                user = await context.Users.FirstOrDefaultAsync(x => x.Username == username);
            }
            return(new RequestResponse <bool>
            {
                Succeeded = true,
                ResponseBody = user == null
            });
        }
示例#5
0
        public async Task <User> SetVerificationStatus(int userId, bool verificationStatus)
        {
            using (var context = new UserEntities())
            {
                var user = await context.Users.FirstOrDefaultAsync(x => x.UserId == userId);

                if (user == null)
                {
                    throw new NotFoundException("User not found");
                }
                user.Email_Verified = verificationStatus ? 1 : 0;
                await context.SaveChangesAsync();

                return(user);
            }
        }
示例#6
0
        public async Task <User> UpdateAccount(string userId, string name, string email)
        {
            using (var context = new UserEntities())
            {
                int.TryParse(userId, out var id);
                var user = await context.Users.FirstOrDefaultAsync(x => x.UserId == id);

                if (user == null)
                {
                    throw new NotFoundException("User not fount");
                }

                user.Email = email;
                user.Name  = name;

                await context.SaveChangesAsync();

                return(user);
            }
        }