/// <summary> /// 刪除角色 /// </summary> /// <param name="requestData"></param> /// <returns></returns> public bool DeleteMutiple(LearningRoleDeleteResquest requestData) { var tokenService = new TokenService(); var tokenInfo = tokenService.GetTokenInfo(requestData.Token).Result; if (tokenInfo == null) { return(false); } var db = _uow.DbContext; var learningCircleService = new LearningCircleService(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(requestData.CircleKey.ToLower()); if (learningCircleInfo == null) { return(false); } var circleMemberService = new Service.Backend.CircleMemberService(); //查出該課程的學生角色 var studentRoleInfo = db.LearningRole.FirstOrDefault(t => t.Level == 3 && t.LearningId == learningCircleInfo.Id && t.IsFixed == false); if (studentRoleInfo == null) { return(false); } foreach (var learningRoleId in requestData.Ids) { var oldLeanirngRole = db.LearningRole.Find(learningRoleId); //查不到或無法修改就跳過 if (oldLeanirngRole == null || oldLeanirngRole.IsFixed == false) { continue; } //將該角色的所有成員全部移至學生Level3 isFixed=false的角色中 var circleMemberDatas = db.CircleMemberRoleplay.Where(t => t.RoleId == learningRoleId && t.CircleId == oldLeanirngRole.LearningId); foreach (var circleMemberData in circleMemberDatas) { circleMemberData.RoleId = studentRoleInfo.Id; } oldLeanirngRole.Enable = false; oldLeanirngRole.Deleted = TimeData.Create(DateTime.UtcNow); oldLeanirngRole.DeleteUser = tokenInfo.MemberId; } db.SaveChanges(); return(true); }
/// <summary> /// 建立多筆 /// </summary> /// <param name="requestData"></param> /// <returns></returns> public IEnumerable <LearningRole> CreateMutiple(LearningRolePostResquest requestData) { var db = _uow.DbContext; var tokenService = new TokenService(); var tokenInfo = tokenService.GetTokenInfo(requestData.Token).Result; if (tokenInfo == null) { return(null); } var learningCircleService = new LearningCircleService(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(requestData.CircleKey.ToLower()); if (learningCircleInfo == null) { return(null); } var responseData = new List <LearningRole>(); foreach (var data in requestData.Roles) { var checkEmpty = db.LearningRole.FirstOrDefault(t => t.Name == data.Name && t.Level == data.Level && t.LearningId == learningCircleInfo.Id); if (checkEmpty != null) { continue; } var entity = new LearningRole() { Created = TimeData.Create(DateTime.UtcNow), Deleted = TimeData.Create(null), Updated = TimeData.Create(null), IsAdminRole = data.Level <= 2 ? true : false, Name = data.Name, Level = data.Level, Enable = true, IsFixed = true, LearningId = learningCircleInfo.Id, CreateUser = tokenInfo.MemberId }; db.LearningRole.Add(entity); responseData.Add(entity); } db.SaveChanges(); return(responseData); }
/// <summary> /// 確認課程管理權限 /// </summary> /// <param name="token"></param> /// <param name="circleKey"></param> /// <returns></returns> public CourseManageAuthResponse CheckCourseManageAuth(string token, string circleKey) { var memberService = new MemberService(); var memberInfo = memberService.TokenToMember(token).Result; if (memberInfo == null) { return(null); } var learningCircleService = new LearningCircleService(); var learningInfo = learningCircleService.GetDetailByOuterKey(circleKey.ToLower()); if (learningInfo == null) { return(null); } var responseData = new CourseManageAuthResponse() { CircleAdminSetting = new CircleAdminSettingAuth(), CircleInfoSetting = new CircleInfoSettingAuth(), CircleMemberSetting = new CircleMemberSettingAuth(), CircleRoleSetting = new CircleRoleSettingAuth(), CircleScheduleSetting = new CircleScheduleSettingAuth(), CircleTimelistSetting = new CircleTimelistSettingAuth() }; //課程管理者 var isCourseManage = CheckCourseAdmin(memberInfo.Id, circleKey); //分類系所管理者 var isDepartmentAdmin = CheckDepartmentAdmin(memberInfo.Id, memberInfo.OrgId); var learningRoleService = new LearningRoleService(); //查看查詢者在課程裡的角色 var myRole = learningRoleService.GetMyRole(token, circleKey); //如果是匯入的課程 if (learningInfo.ExternalRid != null) { responseData = SetCourseManageAuth( //判斷是否為課程管理者 (isCourseManage || ((learningInfo.OrgId.Value == memberInfo.OrgId && memberInfo.IsOrgAdmin) || isDepartmentAdmin)), myRole.Level == 1, //判斷是否為老師身分 myRole.Level == 2, //判斷是否為助教身分 true); //是匯入所以是true return(responseData); } //一般課程管理者 if (isCourseManage || ((learningInfo.OrgId.Value == memberInfo.OrgId && memberInfo.IsOrgAdmin) || isDepartmentAdmin)) { responseData = SetCourseManageAuth(true); return(responseData); } if (myRole == null) { return(null); } switch (myRole.Level) { //如果是老師 case 1: responseData = SetCourseManageAuth(false, true); return(responseData); //如果是助教 case 2: responseData = SetCourseManageAuth(false, false, true); return(responseData); default: return(null); } }
/// <summary> /// 取得角色列表 - 根據circleKey[新結構] /// </summary> /// <param name="circleKey"></param> /// <returns></returns> public IEnumerable <LearningRoleGetResponse> GetLearningRolesByCircleKey(string circleKey, string token) { var db = _uow.DbContext; var learningCircleService = new LearningCircleService(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(circleKey); if (learningCircleInfo == null) { return(null); } var memberService = new MemberService(); var memberInfo = memberService.TokenToMember(token).Result; if (memberInfo == null) { return(null); } var checkTokenLevel = (from lr in db.LearningRole join cmr in db.CircleMemberRoleplay on lr.Id equals cmr.RoleId where cmr.CircleId == learningCircleInfo.Id && cmr.MemberId == memberInfo.Id select lr).FirstOrDefault(); if (checkTokenLevel == null) { return(null); } var responseData = (from lr in db.LearningRole join lc in db.LearningCircle on lr.LearningId equals lc.Id where lc.LearningOuterKey == circleKey && lr.Enable == true select new LearningRoleGetResponse { Level = lr.Level, Name = lr.Name, RoleCode = lr.Ican5Memo, Id = lr.Id, IsFixed = lr.IsFixed, ExternalRid = lr.ExternalRid }).ToList(); if (responseData.FirstOrDefault() == null) { return(null); } var authService = new AuthService(); var isDepartmentAdmin = authService.CheckDepartmentAdmin(memberInfo.Id, memberInfo.OrgId); foreach (var data in responseData) { if (data.ExternalRid.HasValue) { data.IsEdit = false; continue; } if ((isDepartmentAdmin == true || memberInfo.IsOrgAdmin == true)) { data.IsEdit = true; continue; } if (checkTokenLevel.Level.Value < data.Level.Value) { data.IsEdit = true; } else { data.IsEdit = false; } } return(responseData); }