/// <summary> /// Adds a Role /// Level: Logic /// </summary> /// <param name="Role">The Role</param> /// <returns>True if Successful, False if Not</returns> public bool AddRole(string Role) { try { RolesRepository myRepository = new RolesRepository(); if (!myRepository.RoleExists(Role)) { Common.Role myRole = new Role(); myRole.Role1 = Role; myRepository.AddRole(myRole); return true; } else { return false; } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Deletes a Role /// Level: Logic /// </summary> /// <param name="RoleID">The RoleID</param> /// <returns>RoleDeleteEnum</returns> public RoleDelete DeleteRole(int RoleID) { try { RolesRepository myRepository = new RolesRepository(); if (myRepository.RoleIsAdministratorOrUser(RoleID)) { return RoleDelete.LockedRole; } else if (myRepository.RoleHasUsers(RoleID)) { return RoleDelete.HasUsers; } else { myRepository.DeleteRole(RoleID); return RoleDelete.Successful; } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// De Allocates a Role from a User /// Level: Logic /// </summary> /// <param name="Email">The Email</param> /// <param name="RoleID">The RoleID</param> /// <returns></returns> public UserDeAllocate DeAllocateRole(string Email, int RoleID) { try { RolesRepository myRolesRepository = new RolesRepository(); Role myRole = myRolesRepository.RetrieveRoleByID(RoleID); //check if deallocation being done on admin if (myRolesRepository.RetrieveRoleByName("Administrator") != myRole) { if (myRolesRepository.RetrieveRoleByName("User") != myRole) { new UsersRepository().DeAllocateRole(Email, myRole); return UserDeAllocate.Successful; } else { UsersRepository myUsersRepository = new UsersRepository(); if (myUsersRepository.UserIsAdmin(Email)) { new UsersRepository().DeAllocateRole(Email, myRole); return UserDeAllocate.Successful; } else { return UserDeAllocate.OnlyUser; } } } else { return UserDeAllocate.UserIsAdmin; } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Updates a Role /// Level: Logic /// </summary> /// <param name="RoleID">The Role ID</param> /// <param name="Role">The Role</param> /// <returns>RoleUpdate Enum</returns> public RoleUpdate UpdateRole(int RoleID, string Role) { try { RolesRepository myRepository = new RolesRepository(); if (myRepository.RoleIsAdministratorOrUser(RoleID)) { return RoleUpdate.LockedRole; } else if (myRepository.RoleExists(Role)) { return RoleUpdate.SameRole; } else { myRepository.UpdateRole(RoleID, Role); return RoleUpdate.Successful; } } catch (Exception Exception) { throw Exception; } }