コード例 #1
0
        public void CreateExam(ExamBlModel exam, List <int> classroomsList)
        {
            var classrooms = new List <ClassroomBlModel>();

            foreach (var classroomId in classroomsList)
            {
                var classroom = _classroomRepository.GetClassroomById(classroomId);
                classrooms.Add(classroom.GetBlModel());
            }

            var examId = _examRepository.CreateExam(exam.GetDataModel());

            exam.Id = examId;
            var classroomExams = new List <ClassroomExamBlModel>();

            foreach (var classroom in classrooms)
            {
                var classroomExam = new ClassroomExamBlModel()
                {
                    ClassroomId = classroom.Id,
                    ExamId      = exam.Id
                };
                classroomExams.Add(classroomExam);
            }

            exam.ClassroomExams = classroomExams;
            _examRepository.EditExam(exam.GetDataModel());
        }
コード例 #2
0
        public ActionResult Edit(int Id)
        {
            Classroom fResult = new Classroom();
            var       result  = _classroomRepository.GetClassroomById(Id).ToList();

            if (result.Count != 0)
            {
                fResult = result.Select(x => new Classroom()
                {
                    Id             = x.ClassroomId,
                    ClassroomName  = x.ClassroomName,
                    StartDate      = x.StartDate,
                    StartTime      = x.StartTime,
                    EndTime        = x.EndTime,
                    SelectedCourse = x.Courses.CourseId,
                }).Single();
            }
            var allCourses = _courseRepository.Query().Select(x => new Course()
            {
                Id        = x.CourseId,
                ShortName = x.ShortName,
                FullName  = x.FullName
            }).ToList();
            var fromDatabaseEF = new SelectList(allCourses, "Id", "ShortName");

            ViewData["DBMySkills"] = fromDatabaseEF;
            ViewBag.InsigniaList   = new SelectList(allCourses.AsEnumerable(), "Id", "ShortName", Id);

            return(View(fResult));
        }
コード例 #3
0
 public ClassroomBlModel GetClassroomById(int classroomId)
 {
     return(_classroomRepository.GetClassroomById(classroomId).GetBlModel());
 }
コード例 #4
0
        public async Task <BookingAvailability> MaintenanceBooking(IClassroomRepository classroomRepository, IBookingRepository bookingRepository, IUserRepository userRepository,
                                                                   BookingService bookingService, Booking booking, string userId, INotifier notifier)
        {
            var logger = LogManager.GetLogger("ManagementService");

            logger.Info($"Executing Booking request for UserId {userId}");

            var existingLessons = classroomRepository.GetCoursesByRoomAndWeek(booking.Classroom, booking.Week);
            var blockingLessons = bookingService.CourseAvailability(existingLessons, booking);

            logger.Info($"Booking: There are {blockingLessons.Count} blocking lessons");
            if (blockingLessons.Count > 0)
            {
                logger.Info($"There was already a lesson planned during this time for this booking. {blockingLessons.Count}");
                return(BookingAvailability.Scheduled);
            }


            var existingBookings = bookingRepository.GetBookingsByRoomAndWeek(booking.Classroom, booking.Week);
            var blockingBookings = bookingService.BookingAvailability(existingBookings, booking);

            logger.Info($"Booking: There are {blockingBookings.Count} blocking bookings");

            if (blockingBookings.Count > 0)
            {
                var userlist = new List <string>();
                logger.Info($"There was already a booking planned during this time for this booking. {blockingBookings.Count}");
                foreach (var blockingBooking in blockingBookings)
                {
                    var bookingOwner = blockingBooking.Owner;
                    var bookingUser  = userRepository.GetUserById(bookingOwner);
                    if (bookingUser.Role == TimeTableRole.Student)
                    {
                        bookingRepository.DeleteBooking(blockingBooking);
                        if (userlist.Contains(bookingOwner))
                        {
                            continue;
                        }
                        await notifier.Notify(bookingOwner, "Booking cancelled", $"One or more of your bookings have been cancelled due to maintenance in room {blockingBooking.Classroom}", "API");

                        userlist.Add(bookingOwner);
                    }
                }
            }

            existingBookings = bookingRepository.GetBookingsByRoomAndWeek(booking.Classroom, booking.Week);
            var blockingBookingsAfterRemoval = bookingService.BookingAvailability(existingBookings, booking);

            if (blockingBookingsAfterRemoval.Count > 0)
            {
                return(BookingAvailability.Booked);
            }

            logger.Info($"No blocking lessons or bookings. Creating new booking");
            booking.Owner  = userId;
            booking.Lokaal = classroomRepository.GetClassroomById(booking.Classroom);
            booking.Type   = BookingType.Maintenance;
            bookingRepository.CreateBooking(booking);

            logger.Info($"Booking success");
            return(BookingAvailability.Success);
        }