Ejemplo n.º 1
0
 public async Task CreateAccount(User user)
 {
     using (var context = new UserEntities())
     {
         context.Users.Add(user);
         await context.SaveChangesAsync();
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
            });
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }