Exemplo n.º 1
0
        public async Task <bool> Create(ExamRoomExamPeriod examRoomExamPeriod)
        {
            ExamRoomExamPeriodDAO examRoomExamPeriodDAO = examRegContext.ExamRoomExamPeriod
                                                          .Where(s => (s.ExamRoomId.Equals(examRoomExamPeriod.ExamRoomId) && s.ExamPeriodId.Equals(examRoomExamPeriod.ExamPeriodId)))
                                                          .FirstOrDefault();

            if (examRoomExamPeriodDAO == null)
            {
                examRoomExamPeriodDAO = new ExamRoomExamPeriodDAO()
                {
                    ExamRoomId   = examRoomExamPeriod.ExamRoomId,
                    ExamPeriodId = examRoomExamPeriod.ExamPeriodId
                };

                await examRegContext.ExamRoomExamPeriod.AddAsync(examRoomExamPeriodDAO);
            }
            else
            {
                examRoomExamPeriodDAO.ExamRoomId   = examRoomExamPeriod.ExamRoomId;
                examRoomExamPeriodDAO.ExamPeriodId = examRoomExamPeriod.ExamPeriodId;
            };
            await examRegContext.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> RegisterExam(Guid studentId, Guid examPeriodId, Guid termId)
        {
            // nếu sinh viên đã đăng ký thi 1 ca thi của môn đó trước đó thì phải xoá đi đăng ký lại nếu đăng ký ca thi mới của môn đó
            // đếm số lượng exam register để biết sinh viên đã đăng ký ca thi nào đó của môn học đó chưa
            int countExistedExamRegisterOfTerm = await UOW.ExamRegisterRepository.Count(new ExamRegisterFilter
            {
                StudentId = new GuidFilter {
                    Equal = studentId
                },
                TermId = new GuidFilter {
                    Equal = termId
                }
            });

            // nếu đã từng đăng ký thì xoá đi tạo lại
            if (countExistedExamRegisterOfTerm > 0)
            {
                await UOW.ExamRegisterRepository.Delete(studentId, examPeriodId);
            }

            // nếu chưa từng đăng ký thì tạo mới
            // lấy số lượng sinh viên ở trong các phòng thi hiện tại và insert sinh viên vào phòng thi có ít sinh viên nhất
            // nếu số lượng sinh viên trong tất cả các phòng đã đạt max thì báo lỗi

            // Lấy examRoomExamPeriod có số student trong đó ít nhất
            List <ExamRoomExamPeriod> exams = await UOW.ExamRoomExamPeriodRepository.List(new ExamRoomExamPeriodFilter
            {
                ExamPeriodId = new GuidFilter {
                    Equal = examPeriodId
                }
            });

            // Loại exam có số lượng student đạt max, nếu list exam trống thì báo lỗi
            exams.RemoveAll(e => e.Students.Count == e.ExamRoomComputerNumber);
            if (exams.Count == 0)
            {
                return(false);
            }


            // Tiếp tục quy trình nếu list exam còn chỗ trống
            ExamRoomExamPeriod examToRegisterIn = exams
                                                  .Where(exam => exam.Students.Count == exams.Select(e => e.Students.Count).Min())
                                                  .FirstOrDefault();
            // Tạo examRegister mới
            ExamRegister examRegister = new ExamRegister
            {
                StudentId    = studentId,
                ExamPeriodId = examPeriodId,
                ExamRoomId   = examToRegisterIn.ExamRoomId
            };
            await UOW.ExamRegisterRepository.Create(examRegister);

            return(true);
        }
        public async Task <ExamRoomExamPeriod> Delete(ExamRoomExamPeriod examRoomExamPeriod)
        {
            using (UOW.Begin())
            {
                try
                {
                    await UOW.ExamRoomExamPeriodRepository.Delete(examRoomExamPeriod.ExamRoomId, examRoomExamPeriod.ExamPeriodId);

                    await UOW.Commit();
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    examRoomExamPeriod.AddError(nameof(ExamRoomExamPeriodService), nameof(Delete), CommonEnum.ErrorCode.SystemError);
                }
            }
            return(examRoomExamPeriod);
        }
        public async Task <byte[]> ExportStudent(ExamRoomExamPeriodFilter filter)
        {
            // Lấy dữ liệu trong database
            ExamRoomExamPeriod examRoomExamPeriod = await UOW.ExamRoomExamPeriodRepository.Get(filter);

            // Mở excelPackage
            using (ExcelPackage excel = new ExcelPackage())
            {
                // đặt header
                var examRoomExamPeriodHeaders = new List <string[]>()
                {
                    new string[]
                    {
                        "Tên kỳ thi",
                        "Tên môn thi",
                        "Mã số phòng thi",
                        "Tên giảng đường",
                        "Số lượng máy tính",
                        "Ngày thi",
                        "Giờ bắt đầu",
                        "Giờ kết thúc",
                        "Số lượng thí sinh đã đăng kí"
                    },
                    new string[]
                    {
                        examRoomExamPeriod.ExamProgramName,
                        examRoomExamPeriod.SubjectName,
                        examRoomExamPeriod.ExamRoomNumber.ToString(),
                        examRoomExamPeriod.ExamRoomAmphitheaterName,
                        examRoomExamPeriod.ExamRoomComputerNumber.ToString(),
                        examRoomExamPeriod.ExamDate.ToString("dd-MM-yyyy"),
                        examRoomExamPeriod.StartHour.ToString(),
                        examRoomExamPeriod.FinishHour.ToString(),
                        examRoomExamPeriod.Students.Count.ToString()
                    },
                    new string[]
                    {
                        "STT",
                        "Mã số sinh viên",
                        "Họ",
                        "Tên",
                        "Ngày sinh"
                    }
                };
                // tạo data
                List <object[]> data = new List <object[]>();
                for (int i = 0; i < examRoomExamPeriod.Students.Count; i++)
                {
                    data.Add(new object[] {
                        i + 1,
                        examRoomExamPeriod.Students[i].StudentNumber,
                        examRoomExamPeriod.Students[i].LastName,
                        examRoomExamPeriod.Students[i].GivenName,
                        examRoomExamPeriod.Students[i].Birthday.ToString("dd-MM-yyyy")
                    });
                }
                // tạo worksheet
                excel.GenerateWorksheet("Phòng thi - Ca thi", examRoomExamPeriodHeaders, data);
                // trả về dữ liệu dạng byte
                return(excel.GetAsByteArray());
            }
        }