Ejemplo n.º 1
0
        /// <summary>
        /// 虛擬登入
        /// </summary>
        /// <returns></returns>
        public async Task <Guid> SimulationLogin(Guid token, string loginAccount, string sessionId)
        {
            var memberService   = new MemberService();
            var simulatorMember = await memberService.TokenToMember(token);

            if (simulatorMember != null)
            {
                var db = _uow.DbContext;

                var userTokenService = new TokenService();
                //判斷是否有資格模擬登入
                if (simulatorMember.IsOrgAdmin)
                {
                    var loginMember  = db.Members.FirstOrDefault(t => t.Account == loginAccount);
                    var checkedToken = userTokenService.InsertUserToken("iCAN API Viewer", sessionId, loginMember, null, simulatorMember.Id);

                    return(Guid.Parse(checkedToken.Token));
                }
                else
                {
                    return(Guid.Empty);
                }
            }
            else
            {
                return(Guid.Empty);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 設定登入資料
        /// </summary>
        /// <param name="token"></param>
        /// <param name="simulateAccount"></param>
        public SessionData SetMemberSession(Guid token, string simulateAccount = null)
        {
            var db                = _uow.DbContext;
            var memberService     = new MemberService();
            var loginMember       = memberService.TokenToMember(token);
            var courseService     = new CourseService();
            var departmentAdminId = new List <Dept>();

            if (loginMember != null)
            {
                departmentAdminId = courseService.DeptAdminList(loginMember.Result.Id);
                // entity framework
                var dbInfo      = db.Members.Find(loginMember.Result.Id);
                var sessionData = new SessionData
                {
                    LoginAccount    = dbInfo.Account,
                    LoginName       = dbInfo.Name,
                    LoginMemberId   = dbInfo.Id,
                    SimulateAccount = simulateAccount,
                    OrgId           = dbInfo.OrgId,
                    Token           = token,
                    IsOrgAdmin      = dbInfo.IsOrgAdmin,
                    DeptAdminList   = departmentAdminId
                };
                return(sessionData);
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 刪除多筆成員
        /// </summary>
        /// <returns></returns>
        public bool DeleteMultipleMember(MemberManageDeleteRequest requestData)
        {
            var memberService = new MemberService();
            var deleter       = memberService.TokenToMember(requestData.Token).Result;

            if (deleter == null)
            {
                return(false);
            }
            try
            {
                var deleteTargets = (from m in _uow.DbContext.Members
                                     join r in requestData.Members on m.Id equals r
                                     select m);
                foreach (var target in deleteTargets)
                {
                    target.Enable     = false;
                    target.Visibility = false;
                    target.Verified   = false;
                }
                _uow.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 刪除成員角色
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public bool DeleteMemberInfoByAccount(string token, string account)
        {
            try
            {
                var db            = _uow.DbContext;
                var memberService = new MemberService();
                var checkToken    = memberService.TokenToMember(token).Result;
                var memberInfo    = AccountToMember(account, checkToken.OrgId);
                if (memberInfo == null)
                {
                    return(false);
                }

                if (checkToken == null)
                {
                    return(false);
                }
                var result = DeleteMemberInfo(memberInfo.Id, checkToken.Id);

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  取得某使用者的所有身分學習圈
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public IEnumerable <Infrastructure.Entity.LearningCircle> GetLearningCircleListByToken(string token, int?orgId, string searchName)
        {
            var memberService = new MemberService();
            var memberInfo    = memberService.TokenToMember(token).Result;
            var result        = GetLearningCircleListByMemberId(memberInfo.Id, orgId, searchName);

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public Infrastructure.ViewModel.MemberManage.GetCourseMemberInfoResponse APPGetCourseMemberInfo(Infrastructure.ViewModel.MemberManage.GetCourseMemberInfoRequest requestData)
        {
            var memberService = new MemberService();
            var checkToken    = memberService.TokenToMember(requestData.ICanToken).Result;

            if (checkToken == null)
            {
                return(null);
            }

            var memberInfo = AccountToMember(requestData.QueryAccount, checkToken.OrgId);

            if (memberInfo == null)
            {
                return(null);
            }

            var db             = _uow.DbContext;
            var memberRoleInfo = (from cmr in db.CircleMemberRoleplay
                                  join lr in db.LearningRole on cmr.RoleId equals lr.Id
                                  join lc in db.LearningCircle on cmr.CircleId equals lc.Id
                                  where cmr.MemberId == memberInfo.Id && lc.LearningOuterKey == requestData.CircleKey
                                  select lr).ToList().FirstOrDefault();

            if (memberRoleInfo == null)
            {
                return(null);
            }

            var response = new Infrastructure.ViewModel.MemberManage.GetCourseMemberInfoResponse()
            {
                Account          = requestData.QueryAccount,
                Email            = memberInfo.Email,
                Name             = memberInfo.Name,
                Photo            = memberInfo.Photo,
                IsShowEmail      = memberInfo.IsShowEmail,
                GraduationStatus = memberInfo.GraduationStatus,
                Grade            = memberInfo.Grade,
                SchoolRoll       = memberInfo.SchoolRoll,
                RoleName         = memberRoleInfo.Name
            };

            if (memberInfo.DeptId.HasValue)
            {
                var deptInfo = db.Depts.FirstOrDefault(t => t.Id == memberInfo.DeptId.Value);
                response.DeptId           = deptInfo.Id;
                response.CollegeName      = deptInfo.Name;
                response.CollegeBriefName = string.Format("{0} {1}年級", deptInfo.ShortName, memberInfo.Grade);
            }

            return(response);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 取得APP的GetAllMyCourse的資訊
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public IEnumerable <Infrastructure.ViewModel.CourseManage.GetAllMyCourseResponse> APPGetAllMyCourse(string token)
        {
            var memberService = new MemberService();
            var checkToken    = memberService.TokenToMember(token).Result;

            if (checkToken == null)
            {
                return(null);
            }

            var sectionService = new SectionService();
            var sectionData    = sectionService.GetOrgNowSeme(checkToken.OrgId);


            var learningCircleList = GetLearningCircleListByToken(token, null, null);

            if (learningCircleList == null || learningCircleList.Count() <= 0)
            {
                return(new List <Infrastructure.ViewModel.CourseManage.GetAllMyCourseResponse>());
            }
            var response    = new List <Infrastructure.ViewModel.CourseManage.GetAllMyCourseResponse>();
            var sectionYear = learningCircleList.Where(t => t.StartDate.HasValue).GroupBy(t => t.StartDate.Value.Year);

            //上過多少學年度
            foreach (var year in sectionYear)
            {
                var data       = new Infrastructure.ViewModel.CourseManage.GetAllMyCourseResponse();
                var courseData = new List <Infrastructure.ViewModel.CourseManage.DataCourseDataModel>();
                data.Year     = year.Key;
                data.YearSeme = year.Key.ToString();
                if (year.Key == sectionData.Year)
                {
                    data.IsNowSeme = true;
                }
                //查詢課程
                foreach (var learningcircle in learningCircleList.Where(t => t.StartDate.HasValue && ((t.StartDate >= sectionData.StartDate && t.StartDate <= sectionData.EndDate) || (t.EndDate >= sectionData.StartDate && t.EndDate <= sectionData.EndDate))))
                {
                    var learningCircleData = new Infrastructure.ViewModel.CourseManage.DataCourseDataModel();

                    learningCircleData.ClassId          = learningcircle.LearningOuterKey.ToLower();
                    learningCircleData.ClassName        = learningcircle.Name;
                    learningCircleData.ClassSubjectName = learningcircle.Name;
                    //查詢課程老師們
                    var teachers        = memberService.GetTeacherList(learningcircle.LearningOuterKey);
                    var teacherListData = new List <Infrastructure.ViewModel.MemberManage.TeacherPhotoInfo>();
                    var teacherNames    = string.Empty;
                    //設定上課老師們資料
                    foreach (var teacher in teachers)
                    {
                        var teacherData = new Infrastructure.ViewModel.MemberManage.TeacherPhotoInfo();
                        teacherData.Email   = teacher.Email;
                        teacherData.ManName = teacher.Name;
                        teacherData.Url     = teacher.Photo;
                        teacherListData.Add(teacherData);
                        teacherNames += teacher.Name + ",";
                    }
                    teacherNames = teacherNames != string.Empty ? teacherNames.Substring(0, teacherNames.Length - 1) : teacherNames;
                    learningCircleData.TeacherPhoto = teacherListData.ToArray();
                    learningCircleData.ClassTeacher = teacherNames;
                    learningCircleData.StartDate    = learningcircle.StartDate.HasValue ? learningcircle.StartDate.Value.ToLocalTime() : DateTime.MinValue;
                    learningCircleData.EndDate      = learningcircle.EndDate.HasValue ? learningcircle.EndDate.Value.ToLocalTime() : DateTime.MinValue;
                    var memberCount = memberService.GetLearningCircleMembers(learningcircle.LearningOuterKey).Count();
                    learningCircleData.MemberCount = memberCount;
                    var weekTableService = new WeekTableService();
                    var weekDatas        = weekTableService.GetAllMyCourseWeekTableData(learningcircle.Id);
                    if (weekDatas != null)
                    {
                        learningCircleData.WeekTable = weekDatas.ToList();
                    }
                    courseData.Add(learningCircleData);
                }
                data.Course = courseData.ToArray();
                response.Add(data);
            }
            return(response);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public List <Infrastructure.ViewModel.School.GetCampusEventGetResponse> GetList
            (Infrastructure.ViewModel.Base.BackendBaseRequest requestData)
        {
            var db            = _uow.DbContext;
            var responseData  = new List <Infrastructure.ViewModel.School.GetCampusEventGetResponse>();
            var memberService = new MemberService();
            var memberInfo    = memberService.TokenToMember(requestData.Token).Result;

            if (memberInfo == null)
            {
                return(null);
            }

            var sectionService = new SectionService();
            var sectionData    = sectionService.GetOrgNowSeme(memberInfo.OrgId);

            var dbDatas = (from c in db.Calendar
                           join m in db.Members on c.Creator equals m.Id
                           join f in db.FileStorage on c.FileId equals f.Id into ps
                           from o in ps.DefaultIfEmpty()
                           join csg in db.CalendarSemester on c.Id equals csg.CalendarId into csgg
                           from csggt in csgg.DefaultIfEmpty()
                           join cor in db.CalendarOrganizationRole on c.Id equals cor.CalendarId into corg
                           from corgt in corg.DefaultIfEmpty()
                           join cd in db.CalendarDept on c.Id equals cd.CalendarId into cdg
                           from cdgt in cdg.DefaultIfEmpty()
                           where c.OrgId == memberInfo.OrgId && (c.StartDate >= sectionData.StartDate && c.StartDate <= sectionData.EndDate)
                           select new Infrastructure.ViewModel.School.GetCampusEventGetResponse
            {
                Id = c.Id,
                BoarderID = c.Code,
                CreateDate = c.CreateDate.Value,
                CreateMan = m.Account,
                EndDate = c.EndDate,
                IsBigEvent = c.IsBigEvent,
                StartDate = c.StartDate,
                TitleC = c.Title,
                UpdateDate = c.UpdateDate,
                Updater = c.Updater,
                Url = o.FileUrl,
                DeptId = cdgt.DeptId,
                OrganizationRoleId = corgt.OrganizationRoleId,
                SemesterGradeId = csggt.SemesterId
            }).ToList();

            if (dbDatas.FirstOrDefault() == null)
            {
                return(null);
            }

            var memberDept = memberInfo.DeptId.HasValue ? db.Depts.FirstOrDefault(t => t.Id == memberInfo.DeptId.Value) : new Infrastructure.Entity.Dept();
            var memberSemesterGradeInfo = memberInfo.SemesterGradeId.HasValue ? db.SemesterGrade.FirstOrDefault(t => t.Id == memberInfo.SemesterGradeId.Value) : new Infrastructure.Entity.SemesterGrade();
            var memberOrgRoleInfo       = memberInfo.OrganizationRoleId.HasValue ? db.OrganizationRole.FirstOrDefault(t => t.Id == memberInfo.OrganizationRoleId) : new Infrastructure.Entity.OrganizationRole();

            responseData.AddRange(dbDatas);
            //整理資料
            foreach (var dbData in dbDatas)
            {
                if (dbData.Updater.HasValue)
                {
                    dbData.UpdateDate = dbData.UpdateDate.HasValue ? dbData.UpdateDate.Value.ToLocalTime() : dbData.UpdateDate;
                    dbData.UpDateMan  = (dbData.UpDateMan != null && dbData.UpDateMan != string.Empty) ? dbData.UpDateMan : null;
                }
                dbData.CreateDate = dbData.CreateDate.Value.ToLocalTime();
                dbData.StartDate  = dbData.StartDate.ToLocalTime();
                dbData.EndDate    = dbData.EndDate.ToLocalTime();
                dbData.PeriodWeek = GetPeriodWeek(dbData.StartDate, dbData.EndDate, memberInfo.OrgId);
                //假設事件有限制學制顯示
                if (dbData.SemesterGradeId.HasValue)
                {
                    //不是該學制的看不到
                    if (memberSemesterGradeInfo.Id <= 0 || memberSemesterGradeInfo.Id != dbData.SemesterGradeId.Value)
                    {
                        responseData.Remove(dbData);
                    }
                }
                //事件有限制角色顯示
                if (dbData.OrganizationRoleId.HasValue)
                {
                    //不是該角色看不到
                    if (memberOrgRoleInfo.Id <= 0 || memberOrgRoleInfo.Id != dbData.OrganizationRoleId.Value)
                    {
                        responseData.Remove(dbData);
                    }
                }
                //事件有限制學院分類顯示
                if (dbData.DeptId.HasValue)
                {
                    //不屬於該學院分類看不到
                    if (memberDept.Id <= 0 || memberDept.Id != dbData.OrganizationRoleId.Value)
                    {
                        responseData.Remove(dbData);
                    }
                }
            }

            return(responseData);
        }
Ejemplo n.º 10
0
        /// <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);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 註冊帳號
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public UserPostResponse RegisterMember(RegisterRequest data, FileViewModel photo)
        {
            var memberService = new MemberService();
            var creatorInfo   = memberService.TokenToMember(data.Token).Result;

            if (creatorInfo == null)
            {
                return(null);
            }
            var encryptionService = new Encryption();

            var hostUrl = System.Configuration.ConfigurationManager.AppSettings["loginServer"].ToString();


            if (data.OrgCode == null || data.OrgCode == string.Empty)
            {
                data.OrgCode = "amateur";
            }

            var checkRegisted = GetMemberByAccountSchool(data.Account, data.OrgCode);

            //該帳號已經註冊過了
            if (checkRegisted != null)
            {
                return(null);
            }
            var db = _uow.DbContext;
            var organizationInfo = db.Organizations.FirstOrDefault(t => t.OrgCode == data.OrgCode);

            try
            {
                var newMember = new Member()
                {
                    Account     = data.Account,
                    Created     = TimeData.Create(DateTime.UtcNow),
                    Deleted     = TimeData.Create(null),
                    Updated     = TimeData.Create(null),
                    Name        = data.Name,
                    Email       = data.Email,
                    Enable      = true,
                    IsShowEmail = false,
                    Visibility  = true,
                    IsOrgAdmin  = Convert.ToInt32(data.RoleId) == 1 ? true : false,
                    OrgId       = organizationInfo.Id,
                    PassWord    = encryptionService.StringToSHA256(string.Format("{0}{1}", encryptionService.DecryptString(data.Pwd, appKey), data.Account)),
                    Photo       = string.Format("{0}{1}", hostUrl, "images/img-user.png"),
                    RoleName    = data.RoleId.ToString(),
                    Verified    = true,
                    CreateUser  = creatorInfo.Id,
                    ExternalRid = 0
                };
                db.Members.Add(newMember);
                //為了取得memberId
                db.SaveChanges();

                //上傳大頭照
                if (photo != null && photo.ContentLength > 0)
                {
                    var fileService  = new FileService();
                    var maxImgWidth  = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["maxImgWidth"].ToString());
                    var maxImgHeight = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["maxImgHeight"].ToString());
                    var drivePath    = System.Configuration.ConfigurationManager.AppSettings["DrivePath"].ToString();
                    var fileInfo     = fileService.UploadFile(newMember.Id, photo.FileName, photo.ContentType, photo.ContentLength, maxImgHeight, maxImgWidth);
                    var path         = Path.Combine(drivePath, fileInfo.FileGuid.ToString("N"));
                    var stream       = photo.InputStream;
                    /*stream轉bytes*/
                    var br = new BinaryReader(stream);
                    br.BaseStream.Seek(0, SeekOrigin.Begin);
                    var bytesInStream = br.ReadBytes((int)br.BaseStream.Length);
                    //實際檔案處理
                    fileService.FileProxy(photo.ContentLength, path, stream, bytesInStream);
                    newMember.Photo = fileInfo.FileImageUrl;
                    //最終儲存
                    db.SaveChanges();
                }
                var responseData = new UserPostResponse()
                {
                    CreateAccount = creatorInfo.Account,
                    CreateTime    = newMember.Created.Local.Value,
                    Enable        = newMember.Enable,
                    ExternalRid   = newMember.ExternalRid,
                    IsShowMail    = newMember.IsShowEmail,
                    Photo         = newMember.Photo,
                    Verified      = newMember.Verified
                };
                return(responseData);
            }
            catch (Exception ex)
            {
                return(null);

                throw ex;
            }
        }