Esempio n. 1
0
 public static bool IsUserAdmin(string email)
 {
     try
     {
         var users = SQLAdapter.GetUsersByUPN(email);
         if (users == null)
         {
             return(false);
         }
         else
         {
             foreach (UserCourseRoleMapping user in users)
             {
                 if (user.Role.Name != "Student")
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 2
0
        public static UserCourseRoleMappingModel MapToUserModel(UserCourseRoleMapping ucrm)
        {
            if (ucrm == null)
            {
                return(null);
            }
            UserCourseRoleMappingModel user = MapToUserModelOnly(ucrm.User);
            RoleModel role = MapToRoleModel(ucrm.Role);
            var       userCourseRoleModel = new UserCourseRoleMappingModel()
            {
                ID        = ucrm.Id,
                UserId    = ucrm.UserId.ToString(),
                CourseId  = ucrm.CourseId,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                UserName  = user.UserName,
                Email     = user.Email,
                PersonalConversationContactData                                           = ucrm.User.PersonalConversationContactData != null?JsonConvert.DeserializeObject <PersonalConversationContactData>(ucrm.User.PersonalConversationContactData) : null,
                                                                           Role           = role,
                                                                           TutorialGroups = MapToTutorialGroupsModel(ucrm.User.TutorialGroupMemberships.ToList()),
            };
            var  relatedMappingModels = SQLAdapter.GetUsersByUPN(ucrm.User.UserPrincipalName);
            bool isAdmin = false;

            foreach (UserCourseRoleMapping userCourseRoleMapping in relatedMappingModels)
            {
                if (userCourseRoleMapping.Role.Name != "Student")
                {
                    isAdmin = true;
                }
            }
            userCourseRoleModel.IsAdmin = isAdmin;

            if (userCourseRoleModel.Role != null)
            {
                userCourseRoleModel.RoleName = userCourseRoleModel.Role.Name;
            }

            if (userCourseRoleModel.TutorialGroups != null && userCourseRoleModel.TutorialGroups.Count > 0)
            {
                var sb = new StringBuilder("");
                userCourseRoleModel.TutorialGroups.ForEach(tg =>
                {
                    sb.Append(tg.Code);
                    sb.Append(", ");
                });
                sb.Length -= 2;
                userCourseRoleModel.TutorialGroupsString = sb.ToString();
            }
            return(userCourseRoleModel);
        }
Esempio n. 3
0
        public static UserAccessModel GetUserAccess(string upn)
        {
            var result = new UserAccessModel();
            var user   = SQLAdapter.GetUserByUPN(upn);

            if (user == null)
            {
                throw new Exception("User " + upn + " does not exist");
            }

            result.IsGlobalAdmin = user.IsGlobalAdmin == true;

            var userRoleMappings = SQLAdapter.GetUsersByUPN(upn);

            result.IsLecturer     = userRoleMappings.Any(m => m.Role.Name == Constants.LECTURER_ROLE);
            result.IsDemonstrator = userRoleMappings.Any(m => m.Role.Name == Constants.DEMONSTRATOR_ROLE);

            return(result);
        }