Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }