Beispiel #1
0
        public static void AssignUserRole(int userId, UserRoles role)
        {
            User userObject = UserContext.Instance.Users
                              .First(user => user.UserId == userId);

            userObject.Role = role.ToString();
            UserContext.Instance.SaveChanges();
        }
Beispiel #2
0
        public static void AssignUserRole(string username, UserRoles role)
        {
            UserContext context = new UserContext();
            User        user    = context.Users.Where(u => u.Username == username).First();

            if (user != null)
            {
                user.Role = role;
                context.SaveChanges();

                Console.WriteLine(string.Format("User '{0}'s' role changed to '{1}' successfully.", username, role.ToString()));
                Logger.LogActivity(string.Format("Role changed successfully for user '{0}'.", username));

                return;
            }

            Console.WriteLine(string.Format("User '{0}' does not exist. No changes were made", username));
        }