Exemplo n.º 1
0
        /// <summary>
        /// 建立學習圈 - [後臺管理-Area]
        /// </summary>
        /// <param name="data"></param>
        /// <param name="creator"></param>
        /// <returns></returns>
        public LearningCircle InsertLearningCircle(Infrastructure.ViewModel.Backend.LearningCircleViewModel data, int creator)
        {
            try
            {
                var learningRoleService = new LearningRoleService();
                var authService         = new AuthService();
                var db     = _uow.DbContext;
                var entity = data.LearningInfo;
                entity.Updated    = TimeData.Create(null);
                entity.Deleted    = TimeData.Create(null);
                entity.Created    = TimeData.Create(DateTime.UtcNow);
                entity.CreateUser = creator;
                entity.LCType     = 10;
                entity.Visibility = true;
                db.LearningCircle.Add(entity);
                db.SaveChanges();

                //建立老師角色身分
                var teacherRole = learningRoleService.AddLearningEditRole(creator, entity.Id, "老師", true, false, 1);
                //建立助教角色身分
                var surpportTeacherRole = learningRoleService.AddLearningEditRole(creator, entity.Id, "助教", true, false, 2);
                //建立學生角色身分
                var studentRole = learningRoleService.AddLearningEditRole(creator, entity.Id, "學生", false);
                //建立學習圈所有角色的權限
                var insertAuthSuccess = authService.InsertLearningCircleAllRoleAuth(entity.Id, creator);

                # region 新增擴充欄位資訊[目前只有文大有] - 如果是新的學校需要設定新增擴充欄位 [ExtensionColumns資料表]才會有
                if (data.ExtensionInfo != null)
                {
                    foreach (var row in data.ExtensionInfo)
                    {
                        var extValueEntity = new LCExtensionValue();
                        extValueEntity.DataId    = entity.Id;
                        extValueEntity.TextValue = row.Value.TextValue;
                        extValueEntity.ColumnId  = row.Column.Id;
                        db.LCExtensionValue.Add(extValueEntity);
                    }
                    db.SaveChanges();
                }

                #endregion

                return(entity);
            }
Exemplo n.º 2
0
        /// <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;
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }