예제 #1
0
        public IActionResult Voting(Guid sessionId)
        {
            var session = sessionsRepository.Get(sessionId);
            var events  = eventModelBuilder.BuildDateSorted(session.Events, sessionId, authTokenHelper.IsAdmin())
                          .ToList();

            if (!events.Any())
            {
                return(RedirectToAction("AddEvent", "Interaction", new { sessionId }));
            }

            return(View(new SessionModel
            {
                Events = events,
                SessionInfo = new SessionInfoModel
                {
                    SessionId = session.Id,
                    SessionCreateDate = session.CreateDate,
                    SessionName = session.Name
                }
            }));
        }
예제 #2
0
        public IActionResult Reviews(Guid sessionId)
        {
            var session = sessionsRepository.Get(sessionId);

            return(View(new ReviewsModel
            {
                Reviews = session.Reviews
                          .OrderByDescending(x => x.Rating)
                          .Select(x => new ReviewModel
                {
                    Content = x.Content,
                    Rating = x.Rating,
                    Id = x.Id,
                    SessionId = sessionId,
                    AllowModify = authTokenHelper.IsAdmin()
                }),
                SessionInfo = new SessionInfoModel
                {
                    SessionId = session.Id,
                    SessionCreateDate = session.CreateDate,
                    SessionName = session.Name
                }
            }));
        }
예제 #3
0
 public Task <Session> GetByCode([FromRoute] string code)
 {
     return(_sessionRepository.Get(code));
 }
예제 #4
0
        public RegistrationInfoResponse GetRegistrationInfo(long studentId, long sessionId, DateTime checkDateTime)
        {
            Session  session         = _sessionsRepository.Get(sessionId);
            DateTime sessionDateTime = session.Date.Add(session.Time);

            // Если ученик уже зарегистрирован, то обрабатываем по особенному.
            bool isAlreadyRegistered = session.StudentsInSessions.FirstOrDefault(x => x.StudentId == studentId) != null;

            if (!isAlreadyRegistered)
            {
                // Проверяем временные ограничения.
                if (checkDateTime > sessionDateTime.Add(_maxRegistrationDelay))
                {
                    return(GetBadRegisterResponse($"Занятие началось больше {_maxRegistrationDelay.TotalMinutes} минут назад"));
                }

                if (checkDateTime.Date < sessionDateTime.Date.Add(-_maxPreregistrationPeriod))
                {
                    return(GetBadRegisterResponse($"Нельзя записаться на занятие раньше чем за {_maxPreregistrationPeriod.TotalDays} дней"));
                }
            }

            // Разделяем лимитированные и безлимитные абонементы, сортируем по дате окончания их действия.
            // (то, что раньше заканчивается, должно использоваться в первом приоритете)
            Subscription[] allSubscriptions     = _subscriptionsRepository.GetAllActiveSubscriptionsInTime(studentId, sessionDateTime);
            Subscription[] limitedSubscriptions = allSubscriptions
                                                  .Where(x => !x.HasUnlimitedGroup && x.GroupId == session.GroupId)
                                                  .OrderBy(x => x.DateEnd)
                                                  .ToArray();
            Subscription[] unlimitedSubscriptions = allSubscriptions
                                                    .Where(x => x.HasUnlimitedGroup)
                                                    .OrderBy(x => x.DateEnd)
                                                    .ToArray();

            // Проверяем подписки.
            if (!isAlreadyRegistered && limitedSubscriptions.Length == 0 && unlimitedSubscriptions.Length == 0)
            {
                return(GetBadRegisterResponse("У ученика нету абонементов для данной группы"));
            }

            Subscription selectedSubscription = null;

            // Пытаемся найти лимитированный абонемент.
            if (limitedSubscriptions.Length != 0)
            {
                selectedSubscription = limitedSubscriptions.FirstOrDefault(x => x.SubHoursLeft > 0);
            }

            // Если лимитированного нету, пытаемся найти безлимитный.
            if (selectedSubscription == null)
            {
                selectedSubscription = unlimitedSubscriptions.FirstOrDefault(x => x.SubHoursLeft > 0 || x.HasUnlimitedHours);
            }

            if (!isAlreadyRegistered && selectedSubscription == null)
            {
                return(GetBadRegisterResponse("У всех имеющихся абонементов ученика закончились часы"));
            }

            if (isAlreadyRegistered)
            {
                return new RegistrationInfoResponse
                       {
                           IsAlreadyRegistered    = true,
                           IsCanUnregister        = checkDateTime < sessionDateTime.Add(_maxRegistrationDelay),
                           IsRegistrationPossible = false,
                           WarningMessage         = string.Empty,
                           IsSubscriptionFounded  = selectedSubscription != null,
                           Subscription           = selectedSubscription
                       }
            }
            ;

            return(new RegistrationInfoResponse
            {
                IsAlreadyRegistered = false,
                IsCanUnregister = false,
                IsRegistrationPossible = true,
                WarningMessage = string.Empty,
                IsSubscriptionFounded = true,
                Subscription = selectedSubscription
            });
        }