public DayViewModel([NotNull] Day dayData, WeekType weekType, int parity, [NotNull] LessonMenuItemsFactory menuItemsFactory, bool isTeacher, int holderId, NavigationFlow navigationFlow, [CanBeNull] Group group) { if (dayData == null) { throw new ArgumentNullException("dayData"); } if (menuItemsFactory == null) { throw new ArgumentNullException("menuItemsFactory"); } _dayData = dayData; _parity = parity; _isTeacher = isTeacher; _holderId = holderId; _navigationFlow = navigationFlow; _group = @group; _date = SetUpDayName(weekType); NavigationFlow = navigationFlow; if (_dayData.Lessons != null) { Lessons = new ObservableCollection <LessonViewModel>( FilterLessons(_dayData.Lessons, menuItemsFactory)); } else { Lessons = new ObservableCollection <LessonViewModel>(); } }
public LessonViewModel([NotNull] Lesson lesson, [NotNull] LessonMenuItemsFactory menuItemsFactory, DateTime date, NavigationFlow navigationFlow, [CanBeNull] Group group) { _lesson = lesson; _date = date; _navigationFlow = navigationFlow; _group = group; _menuItemsFactory = menuItemsFactory; }
private IEnumerable <LessonViewModel> FilterLessons(IEnumerable <Lesson> lessons, LessonMenuItemsFactory menuItemsFactory) { var ordered = lessons.OrderBy(lesson => lesson.TimeStart); foreach (var lesson in ordered) { if (lesson.Dates != null && lesson.Dates.Any()) { var formattedDay = _date.ToString("dd.MM.yyyy"); if (lesson.Dates.Contains(formattedDay)) { yield return (CreateLessonViewModel(menuItemsFactory, lesson)); } } else { DateTime startDate; DateTime endDate; if (DateTime.TryParse(lesson.DateStart, out startDate) && DateTime.TryParse(lesson.DateEnd, out endDate)) { if (_date < startDate || _date > endDate) { continue; } if (IsVisibleInCurrentWeek(lesson)) { yield return(CreateLessonViewModel(menuItemsFactory, lesson)); } } else { if (IsVisibleInCurrentWeek(lesson)) { yield return(CreateLessonViewModel(menuItemsFactory, lesson)); } } } } }
private void Init(int universityId, int facultyId) { IsLoading = true; _dataProvider.GetUniversityByIdAsync(universityId).Subscribe(university => { _university = university; var menuItemsFactory = new LessonMenuItemsFactory(_commandFactory, _university, Options); _weekViewModelFactory = new WeekViewModelFactory(menuItemsFactory, _isTeacher, _id); if (_isTeacher) { _dataProvider.GetTeacherByIdAsync(universityId, _id).Subscribe(teacher => { _teacher = teacher; Title = (_teacher != null && _teacher.Name != null) ? _teacher.Name.Trim() : string.Empty; UpdateFavoritedSate(); }); LoadLessons(); } else { _dataProvider.GetFacultyByIdAsync(universityId, facultyId).Subscribe(faculty => { _faculty = faculty; //we need to go deeper :) _dataProvider.GetGroupByIdAsync(_facultyId, _id).Subscribe(group => { _group = group; Title = (_group != null && _group.GroupName != null) ? _group.GroupName.Trim() : string.Empty; UpdateFavoritedSate(); }); LoadLessons(); }); } }); }
private LessonViewModel CreateLessonViewModel(LessonMenuItemsFactory menuItemsFactory, Lesson lesson) { return(new LessonViewModel(lesson, menuItemsFactory, _date, _navigationFlow, _group)); }