public void WhenUserSetScheduleOfClassRoomIdFromDateToDateTrueFalse(string userprofileId, string classRoomId, DateTime fromDate, string toDateString, bool isHoliday, bool isShift)
        {
            userprofileId = userprofileId.GetMockStrinValue();
            classRoomId = classRoomId.GetMockStrinValue();

            var mockClassCalendarRepo = ScenarioContext.Current.Get<Mock<IClassCalendarRepository>>();
            mockClassCalendarRepo.Setup(it => it.UpsertClassCalendar(It.IsAny<ClassCalendar>()));

            DateTime toDateValue;
            DateTime? toDate = DateTime.TryParse(toDateString, out toDateValue) ? new Nullable<DateTime>(toDateValue) : null;

            var body = new SetScheduleWithRangeRequest
            {
                ClassRoomId = classRoomId,
                FromDate = fromDate,
                ToDate = toDate,
                IsHoliday = isHoliday,
                IsShift = isShift,
                UserProfileId = userprofileId
            };
            var myCourseCtrl = ScenarioContext.Current.Get<MyCourseController>();
            var result = myCourseCtrl.SetScheduleWithRange(body);
            ScenarioContext.Current.Set(result);
        }
Пример #2
0
        public GetCourseScheduleRespond SetScheduleWithRange(SetScheduleWithRangeRequest body)
        {
            var areArgumentValid = body != null
                && !string.IsNullOrEmpty(body.ClassRoomId)
                && !string.IsNullOrEmpty(body.UserProfileId);
            if (!areArgumentValid) return null;

            var canAccessToCourse = validateAccessToCourseScheduleManagement(body.UserProfileId, body.ClassRoomId);
            if (!canAccessToCourse) return null;

            var classCalendar = _classCalendarRepo.GetClassCalendarByClassRoomId(body.ClassRoomId);
            if (classCalendar == null) return null;

            var requestValid = classCalendar.BeginDate.HasValue;
            if (requestValid)
            {
                var dateRange = Enumerable.Empty<DateTime>();
                var isMoreThanOneDay = body.ToDate.HasValue;
                if (isMoreThanOneDay)
                {
                    var isTodayIsCorrect = body.ToDate.Value > body.FromDate;
                    var fromDate = (isTodayIsCorrect ? body.FromDate : body.ToDate.Value).Date;
                    var toDate = (isTodayIsCorrect ? body.ToDate.Value : body.FromDate).Date;
                    const int ShiftOneDay = 1;
                    var diffDays = (toDate - fromDate).Days + ShiftOneDay;
                    dateRange = Enumerable.Range(0, diffDays).Select(it => fromDate.AddDays(it).ToUniversalTime());
                }
                else dateRange = new List<DateTime> { body.FromDate.Date.ToUniversalTime() };

                var holidays = classCalendar.Holidays ?? Enumerable.Empty<DateTime>();
                holidays = body.IsHoliday ? holidays.Union(dateRange) : holidays.Except(dateRange);
                classCalendar.Holidays = holidays.Distinct();

                var shiftDays = classCalendar.ShiftDays ?? Enumerable.Empty<DateTime>();
                shiftDays = body.IsShift ? shiftDays.Union(dateRange) : shiftDays.Except(dateRange);
                classCalendar.ShiftDays = shiftDays.Distinct();

                classCalendar.CalculateCourseSchedule();
                _classCalendarRepo.UpsertClassCalendar(classCalendar);
            }

            var result = getCourseSchedule(classCalendar, requestValid);
            return result;
        }