Esempio n. 1
0
        public void OnGet()
        {
            var student = JsonConvert.DeserializeObject <Models.Student>(
                User.Claims.First(claim => claim.Type == "Information").Value);
            var kuasAp = new Services.KUASAPService();

            // Set SysValue default value
            if (string.IsNullOrEmpty(SysValue))
            {
                SysValue = $"{ student.SysYear },{ student.SysSemester }";
            }

            // DropDownList items
            SysValues = new List <SelectListItem>();
            kuasAp.GetOptionValueList(student: student).ForEach(sysItem =>
                                                                SysValues.Add(new SelectListItem()
            {
                Text     = sysItem.SysText,
                Value    = $"{ sysItem.SysYear },{ sysItem.SysSemester }",
                Selected = string.IsNullOrEmpty(SysValue) ?
                           (sysItem.SysYear == student.SysYear && sysItem.SysSemester == student.SysSemester) :
                           (sysItem.SysYear == SysValue.Split(',')[0] && sysItem.SysSemester == SysValue.Split(',')[1])
            }));

            // Course list
            kuasAp.GetCourseListAndSchedule(
                student: student,
                year: SysValue.Split(',')[0],
                semester: SysValue.Split(',')[1]);
            CourseList = new List <Models.Class>(kuasAp.CourseList);
            Schedule   = new List <List <Models.Class> >(kuasAp.Schedule);

            // If empty, display alert
            if (CourseList.Count <= 0)
            {
                ModelState.AddModelError("Warning", $"查無 { SysValues.First(item => item.Selected).Text } 之課程資訊");
            }
        }
Esempio n. 2
0
        public void OnGet()
        {
            var student = JsonConvert.DeserializeObject <Models.Student>(
                User.Claims.First(claim => claim.Type == "Information").Value);
            var kuasAp = new Services.KUASAPService();

            // Set SysValue default value
            if (string.IsNullOrEmpty(SysValue))
            {
                SysValue = $"{ student.SysYear },{ student.SysSemester }";
            }

            // DropDownList items
            DropDownList = new List <SelectListItem>();
            kuasAp.GetOptionValueList(student: student).ForEach(sysItem =>
                                                                DropDownList.Add(new SelectListItem()
            {
                Text     = sysItem.SysText,
                Value    = $"{ sysItem.SysYear },{ sysItem.SysSemester }",
                Selected = string.IsNullOrEmpty(SysValue) ?
                           (sysItem.SysYear == student.SysYear && sysItem.SysSemester == student.SysSemester) :
                           (sysItem.SysYear == SysValue.Split(',')[0] && sysItem.SysSemester == SysValue.Split(',')[1])
            }));

            // Miss classes
            MissClasses = kuasAp.GetMissClasses(
                student: student,
                year: SysValue.Split(',')[0],
                semester: SysValue.Split(',')[1],
                fillFullSapce: true);


            // If empty, display alert
            if (MissClasses.Count <= 0)
            {
                ModelState.AddModelError("Warning", $"查無 { DropDownList.First(item => item.Selected).Text } 之學期缺曠");
            }
        }
Esempio n. 3
0
        public async Task OnGetAsync()
        {
            // Message by redirect
            if (TempData.ContainsKey("Error"))
            {
                ModelState.AddModelError("Error", TempData["Error"].ToString());
            }

            var student = JsonConvert.DeserializeObject <Models.Student>(
                User.Claims.First(claim => claim.Type == "Information").Value);
            var kuasAp = new Services.KUASAPService();

            // Set SysValue default value
            if (string.IsNullOrEmpty(SysValue))
            {
                SysValue = $"{ student.SysYear },{ student.SysSemester }";
            }

            // DropDownList items
            SysValues = new List <SelectListItem>();
            kuasAp.GetOptionValueList(student: student).ForEach(sysItem =>
                                                                SysValues.Add(new SelectListItem()
            {
                Text     = sysItem.SysText,
                Value    = $"{ sysItem.SysYear },{ sysItem.SysSemester }",
                Selected = string.IsNullOrEmpty(SysValue) ?
                           (sysItem.SysYear == student.SysYear && sysItem.SysSemester == student.SysSemester) :
                           (sysItem.SysYear == SysValue.Split(',')[0] && sysItem.SysSemester == SysValue.Split(',')[1])
            }));

            // Course list
            kuasAp.GetCourseListAndSchedule(
                student: student,
                year: SysValue.Split(',')[0],
                semester: SysValue.Split(',')[1]);
            CourseList = new List <Models.Class>(kuasAp.CourseList);
            Schedule   = new List <List <Models.Class> >(kuasAp.Schedule);

            // If empty, display alert
            if (CourseList.Count <= 0)
            {
                ModelState.AddModelError("Warning", $"查無 { SysValues.First(item => item.Selected).Text } 之課程資訊");
            }
            else
            {
                // 跨校選課不得撰寫評論
                CourseList.ForEach(course => course.DoneComment = course.ClassShortName.Contains("跨外校"));
                Schedule.ForEach(courses => courses.ForEach(course => course.DoneComment = string.IsNullOrEmpty(course.ClassShortName) ? course.DoneComment : course.ClassShortName.Contains("跨外校")));

                // 尋找是否存在已經寫過的評論
                // Repositorys
                var classRepository   = new Repositorys.ClassRepository(appSettings.ConnectionStrings.DefaultConnection);
                var commentRepository = new Repositorys.CommentRepository(appSettings.ConnectionStrings.DefaultConnection);
                // // 搜尋使用者的評論
                var comments = (await commentRepository.Select(comment: new Models.Comment()
                {
                    Creator = student.Username
                })).ToList();
                // // 巡迴所有評論
                foreach (var comment in comments)
                {
                    // 取得評論之課程資料
                    Models.Class @class = (await classRepository.Select(@class: new Models.Class()
                    {
                        Guid = comment.ClassGuid
                    })).ToList().First();
                    // 選課清單
                    CourseList.ForEach(course =>
                                       course.DoneComment = course.DoneComment ||
                                                            (course.SubjectChineseName == @class.SubjectChineseName && course.Teachers == @class.Teachers && course.ClassShortName == @class.ClassShortName));
                    // 課表
                    Schedule.ForEach(courses => courses.ForEach(course =>
                                                                course.DoneComment = course.DoneComment ||
                                                                                     (course.SubjectChineseName == @class.SubjectChineseName && course.Teachers == @class.Teachers && course.ClassShortName == @class.ClassShortName)));
                }
            }
        }
Esempio n. 4
0
        public void OnGet()
        {
            var student = JsonConvert.DeserializeObject <Models.Student>(
                User.Claims.First(claim => claim.Type == "Information").Value);
            var kuasAp       = new Services.KUASAPService();
            var sysValueList = kuasAp.GetOptionValueList(student: student);
            var scores       = new List <Models.Score>();

            var subject = new Dictionary <string, List <Models.Score> >()
            {
                { "Get", new List <Models.Score>() },
                { "Miss", new List <Models.Score>() }
            };
            var generalEducation = new Dictionary <string, List <Models.Score> >()
            {
                { "Core", new List <Models.Score>() },
                { "Extend", new List <Models.Score>() }
            };

            for (int i = 0, countOfEmpty = 0; countOfEmpty < 10; i++)
            {
                var tmpScores = kuasAp.GetScores(student: student, year: sysValueList[i].SysYear, semester: sysValueList[i].SysSemester).Scores;
                if (tmpScores.Count <= 0)
                {
                    countOfEmpty++;
                }
                else
                {
                    scores.AddRange(tmpScores);
                    countOfEmpty = 0;
                }
            }
            if (scores.Count > 0)
            {
                foreach (Models.Score score in scores)
                {
                    if (!string.IsNullOrEmpty(score.SemesterScore))
                    {
                        if (score.SemesterScore == "合格")
                        {
                            subject["Get"].Add(score);
                        }
                        else if (score.SemesterScore.Contains("*") && score.IsRequired)
                        {
                            subject["Miss"].Add(score);
                        }
                        else if (score.SemesterScore.Contains("不合格") && score.IsRequired)
                        {
                            subject["Miss"].Add(score);
                        }
                        else if (float.Parse(score.SemesterScore) < 60)
                        {
                            subject["Miss"].Add(score);
                        }
                        else
                        {
                            subject["Get"].Add(score);
                            if (score.SubjectChineseName.Contains("核心通識"))
                            {
                                generalEducation["Core"].Add(score);
                            }
                            else if (score.SubjectChineseName.Contains("延伸通識"))
                            {
                                generalEducation["Extend"].Add(score);
                            }
                        }
                    }
                }
            }

            // 刪除課程中的通識課程
            subject["Get"].RemoveAll(x => x.SubjectChineseName.Contains("通識"));
            subject["Miss"].RemoveAll(x => x.SubjectChineseName.Contains("通識"));

            // 刪除重複已失去課程
            foreach (Models.Score score in subject["Miss"].ToArray())
            {
                // 建立暫存課程
                Models.Score temp = score;
                // 尋找是否有重複 (2 個以上) 項目
                if (subject["Miss"].FindAll(x => x.SubjectChineseName == temp.SubjectChineseName &&
                                            x.PropertiesCredit == temp.PropertiesCredit &&
                                            x.PropertiesRequiredOrElective == temp.PropertiesRequiredOrElective).Count > 1)
                {
                    // 若有則全數移除並重新加入
                    subject["Miss"].RemoveAll(x => x.SubjectChineseName == temp.SubjectChineseName &&
                                              x.PropertiesCredit == temp.PropertiesCredit &&
                                              x.PropertiesRequiredOrElective == temp.PropertiesRequiredOrElective);
                    subject["Miss"].Add(temp);
                }
            }

            // 重修已及格修正
            foreach (Models.Score score in subject["Get"].ToArray())
            {
                if (subject["Miss"].FindAll(x => x.SubjectChineseName == score.SubjectChineseName &&
                                            x.PropertiesCredit == score.PropertiesCredit &&
                                            x.PropertiesRequiredOrElective == score.PropertiesRequiredOrElective).Count > 0)
                {
                    subject["Miss"].RemoveAll(x => x.SubjectChineseName == score.SubjectChineseName &&
                                              x.PropertiesCredit == score.PropertiesCredit &&
                                              x.PropertiesRequiredOrElective == score.PropertiesRequiredOrElective);
                }
            }

            // 對 subject 做排序
            foreach (string key in subject.Keys.ToArray())
            {
                subject[key] = subject[key].OrderBy(x => float.Parse(x.PropertiesCredit))
                               .ThenBy(x => x.SubjectChineseName)
                               .ThenBy(x => float.Parse(x.TeachTime))
                               .ThenBy(x => x.PropertiesRequiredOrElective)
                               .ThenBy(x => x.ClassType)
                               .ThenBy(x => x.MidtermScore)
                               .ThenBy(x => x.SemesterScore)
                               .ThenBy(x => x.Remark).ToList();
            }
            // 對 generalEducation 以自定義做排序
            foreach (string key in generalEducation.Keys.ToArray())
            {
                generalEducation[key].Sort((x, y) => new OrderBySubjectChtName().Compare(x.SubjectChineseName, y.SubjectChineseName));
            }

            Credits = new Models.Credits()
            {
                Subject          = subject,
                GeneralEducation = generalEducation
            };
            // 已取得所有學分
            GetCredits = (int)subject["Get"].Sum(x => float.Parse(x.PropertiesCredit));
            // 已取得必修學分
            GetRequiredCredits = (int)subject["Get"].FindAll(x => x.IsRequired).Sum(x => float.Parse(x.PropertiesCredit));
            // 已取得選修學分
            GetNotRequiredCredits = (int)subject["Get"].FindAll(x => !x.IsRequired).Sum(x => float.Parse(x.PropertiesCredit));
            // 已失去必修學分
            MissRequiredCredits = (int)subject["Miss"].Sum(x => float.Parse(x.PropertiesCredit));
        }