コード例 #1
0
        public SemesterDetail GetById(int id)
        {
            //SemesterExam semesterExam = context.SemesterExams.Include(SE => SE.);
            //var query = from SE in context.SemesterExams.Include(SE.)
            //            where SE.ID == id
            //            select SE;
            context.Configuration.LazyLoadingEnabled = false;
            List <User>         users              = context.Users.ToList();
            List <SemesterExam> semesterExams      = context.SemesterExams.ToList();
            SemesterExam_User   semesterExam_Users =
                context.SemesterExamUsers.Where(SU => SU.SemesterExam.ID == id && SU.Type == 1).FirstOrDefault();
            SemesterExam   semesterExam   = context.SemesterExams.Find(id);
            SemesterDetail semesterDetail = new SemesterDetail();

            try
            {
                semesterDetail.ID           = semesterExam.ID;
                semesterDetail.SemesterName = semesterExam.SemesterName;
                if (semesterExam.StartDay != null)
                {
                }

                semesterDetail.StartDay = semesterExam.StartDay.ToString();
                semesterDetail.EndDay   = semesterExam.EndDay.ToString();
                if (semesterExam_Users != null)
                {
                    semesterDetail.Creator = semesterExam_Users.User.FullName;
                }
                semesterDetail.Code = semesterExam.Code;
                if (semesterExam.status == 1)
                {
                    semesterDetail.status = "Public";
                }
                if (semesterExam.status == 2)
                {
                    semesterDetail.status = "Draft";
                }
                if (semesterExam.status == 0)
                {
                    semesterDetail.status = "Done";
                }

                var QT = from TR in context.TestResults
                         join U in context.Users on TR.UserId equals U.UserId
                         join SU in context.SemesterExamUsers on U.UserId equals SU.User.UserId
                         where SU.Type == 2 && SU.SemesterExam.ID == id
                         select TR;
                int participation = QT.ToList().Count;
                semesterDetail.NumberInvite = Convert.ToString(participation);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }



            return(semesterDetail);
        }
コード例 #2
0
        public Model.ViewModel.ReportSemester Report(int id)
        {
            SemesterExam      semesterExam       = context.SemesterExams.Find(id);
            SemesterExam_User semesterExam_Users =
                context.SemesterExamUsers.Where(SU => SU.SemesterExam.ID == id && SU.Type == 1).FirstOrDefault();
            var query = from E in context.Exams
                        join T in context.Tests on E.Id equals T.ExamId
                        join SE in context.SemesterExamUsers on T.ExamId equals SE.ID
                        select E;
            //var queryCandiates = from SEU in context.SemesterExamUsers
            //    join SE in context.SemesterExams on SEU.SemesterExam.ID equals id
            //    //where SEU.Type == 2
            //    select SEU;
            int numCandiates = context.SemesterExamUsers.Where(SEU => SEU.SemesterExam.ID == id && SEU.Type == 2)
                               .ToList().Count;
            List <SemesterExam_User> list = context.SemesterExamUsers
                                            .Where(SEU => SEU.SemesterExam.ID == id && SEU.Type == 2).ToList();

            var QT = from TR in context.TestResults
                     join U in context.Users on TR.UserId equals U.UserId
                     join SU in context.SemesterExamUsers on U.UserId equals SU.User.UserId
                     where SU.Type == 2 && SU.SemesterExam.ID == id
                     select TR;
            int low    = 0;
            int medium = 0;
            int good   = 0;

            foreach (TestResult item in QT.ToList())
            {
                if (item.Score < 4)
                {
                    low++;
                }

                if (item.Score > 7)
                {
                    good++;
                }
                else
                {
                    medium++;
                }
            }

            float avgScore = 0;

            foreach (TestResult item in QT.ToList())
            {
                avgScore += item.Score;
            }

            avgScore = avgScore / QT.ToList().Count;
            int participation = QT.ToList().Count;
            int count         = 0;

            if (query.ToList() != null)
            {
                count = query.ToList().Count;
            }
            Exam exam        = query.ToList().FirstOrDefault();
            int  numQuestion = 0;

            if (exam != null)
            {
                numQuestion = exam.QuestionNumber;
            }



            ReportSemester reportSemester = new ReportSemester();

            User user = new User();
            //user.SemesterExam_Users.Where(S => S.ID == 1).ToList();
            //SemesterExam semesterExam= new SemesterExam();
            List <User>         users = context.Users.ToList();
            List <SemesterExam> semesterExamsterExams = context.SemesterExams.ToList();

            reportSemester.SemesterName = semesterExam.SemesterName;
            if (semesterExam_Users != null)
            {
                reportSemester.Creator = semesterExam_Users.User.FullName;
            }
            reportSemester.StartDay         = semesterExam.StartDay.ToString();
            reportSemester.EndDay           = semesterExam.EndDay.ToString();
            reportSemester.NumEXams         = count;
            reportSemester.NumQuestions     = numQuestion;
            reportSemester.NumCandiates     = numCandiates;
            reportSemester.NotParticipation = numCandiates - participation;
            reportSemester.AvgScore         = avgScore;
            reportSemester.Good             = good;
            reportSemester.Medium           = medium;
            reportSemester.Low = low;
            if (semesterExam.status == 1)
            {
                reportSemester.Status = "Public";
            }
            if (semesterExam.status == 2)
            {
                reportSemester.Status = "Draft";
            }
            else
            {
                reportSemester.Status = "Done";
            }
            //ReportSemester reportSemester = new ReportSemester(semesterExam.SemesterName,semesterExam_Users.User.UserName,semesterExam.StartDay.ToString(),semesterExam.EndDay.ToString(),count);
            return(reportSemester);
        }