/// <summary> /// 設定角色在學習圈內的權限 /// </summary> /// <param name="learningRoleId">角色關聯代碼</param> /// <param name="functionId">功能代碼</param> /// <param name="setAuth">調整權限</param> /// <param name="memberId">修改人</param> /// <returns></returns> public LearningAuth SetLearningSectionAuth(int learningRoleId, int functionId, bool setAuth, int memberId) { var db = _uow.DbContext; //判斷是否已設定過權限 var checkAuth = db.LearningAuth.Where(t => t.FunctionId.Equals(functionId) && t.LearningRoleId.Equals(learningRoleId)); var entity = new LearningAuth(); //直接修改權限 if (checkAuth.Any()) { entity = checkAuth.ToList()[0]; entity.Enable = setAuth; db.SaveChanges(); } //新增權限 else { entity = AddLearningAuth(learningRoleId, functionId, memberId); } //取得新的token資料 var result = db.LearningAuth.Find(entity.Id); return(result); }
/// <summary> /// 新增某個學習圈的所有角色權限 /// </summary> /// <param name="learningCircleId">學習圈編號</param> /// <param name="creator">建立者編號</param> /// <returns></returns> public bool InsertLearningCircleAllRoleAuth(int learningCircleId, int creator) { try { var roleService = new LearningRoleService(); var db = _uow.DbContext; //查詢學習圈所有角色 var roles = roleService.GetLearningCircleRoles(learningCircleId); foreach (var role in roles) { //查詢該角色欲新增的權限 var moduleFunctions = (role.IsAdminRole) ? db.ModuleFunction.Where(t => t.IsAdminAuth == true) : db.ModuleFunction.Where(t => t.IsNormalAuth == true); //開始新增權限 foreach (var auth in moduleFunctions) { var entity = new LearningAuth { LearningRoleId = role.Id, FunctionId = auth.Id, Enable = true, Created = Infrastructure.Property.TimeData.Create(DateTime.UtcNow), CreateUser = creator, UpdateUser = null, DeleteUser = null, Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null) }; db.LearningAuth.Add(entity); } } db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
/// <summary> /// 新增學習圈權限 /// </summary> /// <param name="learningRoleId"></param> /// <param name="functionId"></param> /// <param name="memberId"></param> /// <returns></returns> public LearningAuth AddLearningAuth(int learningRoleId, int functionId, int memberId) { var db = _uow.DbContext; var entity = new LearningAuth { LearningRoleId = learningRoleId, FunctionId = functionId, Enable = true, Created = Infrastructure.Property.TimeData.Create(DateTime.UtcNow), CreateUser = memberId, UpdateUser = null, DeleteUser = null, Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null) }; db.LearningAuth.Add(entity); db.SaveChanges(); //取得新的token資料 var result = db.LearningAuth.Find(entity.Id); return(result); }