public LessonInfo GetLessonInfo(int schoolLevel)
        {
            var lessons     = Repository.GetLessons(schoolLevel).OrderBy(l => l.StartTime).ToArray();
            var currentTime = DateTime.Now.TimeOfDay;

            if (lessons[lessons.Length - 1].EndTime <currentTime || lessons[0].StartTime> currentTime)
            {
                return(LessonInfo.AsLessonsEnded());
            }

            for (int i = 0; i < lessons.Length; i++)
            {
                if (lessons[i].StartTime <= currentTime && currentTime <= lessons[i].EndTime)
                {
                    var minutes = (int)Math.Round((lessons[i].EndTime - currentTime).TotalMinutes, MidpointRounding.AwayFromZero);
                    var perc    = 100 - (minutes * 100 / (lessons[i].EndTime.TotalMinutes - lessons[i].StartTime.TotalMinutes));
                    return(LessonInfo.AsLesson(lessons[i].Description, minutes, (int)perc));
                }

                if (lessons[i].EndTime < currentTime && currentTime < lessons[i + 1].StartTime)
                {
                    var minutes = (int)Math.Round((lessons[i + 1].StartTime - currentTime).TotalMinutes, MidpointRounding.AwayFromZero);
                    var perc    = 100 - (minutes * 100 / (lessons[i + 1].StartTime.TotalMinutes - lessons[i].EndTime.TotalMinutes));
                    return(LessonInfo.AsBreak(minutes, (int)perc));
                }
            }

            return(null);
        }
        private void DisplayEventDetails(Event ev)
        {
            if (ev == null)
            {
                return;
            }
            string nl = Environment.NewLine;

            LessonInfo lessonInfo = timetableInfo.LessonsInfo.FirstOrDefault(li => li.Lesson == ev.Lesson);
            string     notes      = null;

            if (lessonInfo != null)
            {
                if (!string.IsNullOrEmpty(lessonInfo.Notes))
                {
                    notes = nl + nl + lessonInfo.Notes;
                }
            }
            DisplayAlert($"{ev.Lesson.FullName}", string.Format(LN.EventType, ev.Type.FullName) + nl +
                         string.Format(LN.EventClassroom, ev.RoomName) + nl +
                         string.Format(LN.EventTeachers, string.Join(", ", ev.Teachers.Select(t => t.Name))) + nl +
                         string.Format(LN.EventGroups, string.Join(", ", ev.Groups.Select(t => t.Name))) + nl +
                         string.Format(LN.EventDay, ev.Start.ToString("ddd, dd.MM.yy")) + nl +
                         string.Format(LN.EventTime, ev.Start.ToString("HH:mm"), ev.End.ToString("HH:mm")) +
                         notes, LN.Ok);
        }
        public EventPopupViewModel(Event ev, TimetableInfoList timetable)
        {
            Event = ev;

            ClosePopupCommand    = CommandFactory.Create(ClosePopup);
            AddToCalendarCommand = CommandFactory.Create(AddEventToCalendar);

            LessonInfo lessonInfo = timetable.LessonsInfo.FirstOrDefault(li => li.Lesson.Equals(ev.Lesson));

            Notes = lessonInfo?.Notes;

            EventNumber = timetable.Events
                          .Where(e => e.Lesson == ev.Lesson && e.Type == ev.Type && e.Start < ev.Start)
                          .DistinctBy(e => e.Start)
                          .Count() + 1;
            EventsCount = timetable.Events
                          .Where(e => e.Lesson == ev.Lesson && e.Type == ev.Type)
                          .DistinctBy(e => e.Start)
                          .Count();

            Details = $"{string.Format(LN.EventType, ev.Type.FullName)} ({EventNumber}/{EventsCount})\n" +
                      $"{string.Format(LN.EventClassroom, ev.RoomName)}\n" +
                      $"{string.Format(LN.EventTeachers, string.Join(", ", ev.Teachers.Select(t => t.Name)))}\n" +
                      $"{string.Format(LN.EventGroups, string.Join(", ", ev.Groups.Select(t => t.Name)))}\n" +
                      $"{string.Format(LN.EventDay, ev.Start.ToString("ddd, dd.MM.yy"))}\n" +
                      $"{string.Format(LN.EventTime, ev.Start.ToString("HH:mm"), ev.End.ToString("HH:mm"))}";
        }
        private async Task GetLessonDetail(LessonInfo selectedLessonInfo)
        {
            ResponseResult lessonDetail = await _bmsService.GetLessonById(selectedLessonInfo.Id.ToString());

            if (!HasErrorMsg(lessonDetail.Status, lessonDetail.Message))
            {
                CurLessonDetail = lessonDetail.Data as LessonDetail;

                if (CurLessonDetail != null)
                {
                    CurLessonDetail.LessonType = selectedLessonInfo.LessonType;

                    DetailVisibility = Visibility.Visible;

                    IsTeacher = CurLessonDetail.MasterUserId ==
                                IoC.Get <UserInfo>().UserId
                        ? "(你是主讲)"
                        : string.Empty;

                    MainPoint = CurLessonDetail.MainPoint;

                    DateTime now = DateTime.Now;
                    if (now >= CurLessonDetail.StartTime.AddMinutes(-20) &&
                        now <= CurLessonDetail.EndTime.AddMinutes(20))
                    {
                        ParticipateVisibility = Visibility.Visible;
                    }
                    else
                    {
                        ParticipateVisibility = Visibility.Collapsed;
                    }
                }
            }
        }
        private async Task GetAttendees(LessonInfo selectedLessonInfo)
        {
            ResponseResult attendeesResult =
                await _bmsService.GetUsersByLessonId(selectedLessonInfo.Id.ToString());

            if (!HasErrorMsg(attendeesResult.Status, attendeesResult.Message))
            {
                List <UserInfo> attendees = attendeesResult.Data as List <UserInfo>;

                if (attendees != null)
                {
                    List <UserInfo> globalUserInfos = IoC.Get <List <UserInfo> >();
                    globalUserInfos.Clear();

                    Attendees.Clear();
                    attendees.ForEach(attendee =>
                    {
                        Attendees.Add(attendee);
                        globalUserInfos.Add(attendee);
                    });

                    AttendeesCount = string.Format($"(共{Attendees.Count}人)");

                    var masterUser =
                        Attendees.FirstOrDefault(userInfo => userInfo.UserId == CurLessonDetail?.MasterUserId);

                    if (masterUser != null)
                    {
                        masterUser.IsTeacher = true;
                    }
                }
            }
        }
Esempio n. 6
0
        public LessonInfoViewModel(LessonInfo lessonInfo, TimetableInfo timetableInfo)
        {
            LessonInfo         = lessonInfo;
            this.timetableInfo = timetableInfo;
            Statistics         = new(GetStatistics);

            LocalizationResourceManager.Current.PropertyChanged += (_, _) => OnPropertyChanged(nameof(Statistics));
        }
Esempio n. 7
0
 public void UpdateLessonInfo(LessonInfo lessonInfo)
 {
     ThrowIfDisposed();
     if (lessonInfo == null)
     {
         throw new ArgumentNullException("lessonInfo");
     }
     _lessonInfoStore.Update(lessonInfo);
 }
Esempio n. 8
0
 public LessonInfo DeleteLessonInfo(LessonInfo lessonInfo)
 {
     ThrowIfDisposed();
     if (lessonInfo == null)
     {
         throw new ArgumentNullException("lessonInfo");
     }
     return(_lessonInfoStore.Delete(lessonInfo));
 }
        private async Task SelectionChangedAsync(LessonInfo selectedLessonInfo)
        {
            if (selectedLessonInfo == null || selectedLessonInfo.Id == 0)
            {
                return;
            }

            await GetLessonDetail(selectedLessonInfo);
            await GetAttendees(selectedLessonInfo);

            await _groupManager.JoinGroup(selectedLessonInfo.Code, GlobalResources.DiscussionContentView);
        }
Esempio n. 10
0
 public LessonInfo GetUGTULesson(int LessonNum)
 {
     using (DataLayer.ScheduleDataDataContext ctx = new DataLayer.ScheduleDataDataContext("Data Source=ugtudb.ugtu.net;Initial Catalog=UGTU;Integrated Security=True"))
     {
         LessonInfo li = ctx.SheduleEventTypes.Where(p => (p.ik_event_type == LessonNum)).Select(x =>
                                                                                                 new LessonInfo()
         {
             ID   = x.ik_event_type, Name = x.cName_event, Begins = x.dEvent_start,
             Ends = x.dEvent_stop
         }).Single();
         return(li);
     }
 }
        public void GroupLessonsExcludeIndividual()
        {
            var groups = new[] { "1", "2" };
            var scheduleUpdaterMock  = new Mock <IScheduleUpdater>();
            var selectionUpdaterMock = new Mock <IStudentSelectionUpdater>();

            var lessonInfo1 = new LessonInfo
            {
                Subject = "l1",
                Group   = "g1"
            };

            var lessonInfo2 = new LessonInfo
            {
                Subject = "l2",
                Group   = "g2"
            };
            var lessonInfo3 = new LessonInfo
            {
                Subject = "l3",
                Group   = "g1"
            };

            scheduleUpdaterMock.Setup(x => x.UpdateSchedule(It.Is <string[]>(s => s == groups)))
            .Returns(new[]
            {
                lessonInfo1,
                lessonInfo2,
                lessonInfo3
            });

            selectionUpdaterMock.Setup(x => x.Update())
            .Returns(new List <StudentSelection>
            {
                new StudentSelection
                {
                    Group          = "g1",
                    Name           = "name",
                    SpecCourseName = lessonInfo1.Subject
                }
            });

            var individualScheduleBuilder = new IndividualScheduleBuilder(scheduleUpdaterMock.Object, selectionUpdaterMock.Object);
            var updateIndividualSchedule  = individualScheduleBuilder.UpdateIndividualSchedule(groups);

            Assert.That(updateIndividualSchedule.GroupsLessons, Contains.Key(lessonInfo1.Group));
            Assert.That(updateIndividualSchedule.GroupsLessons, Contains.Key(lessonInfo2.Group));

            CollectionAssert.AreEquivalent(new[] { lessonInfo3 }, updateIndividualSchedule.GroupsLessons[lessonInfo1.Group]);
            CollectionAssert.AreEquivalent(new[] { lessonInfo2 }, updateIndividualSchedule.GroupsLessons[lessonInfo2.Group]);
        }
        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null || !(e.Item is LessonInfo))
            {
                return;
            }

            LessonInfo selectedLesson = (LessonInfo)e.Item;

            //Deselect Item
            ((ListView)sender).SelectedItem = null;

            await Navigation.PushAsync(new LessonSettingsPage(selectedLesson, timetable.EventTypes(selectedLesson.Lesson.ID).ToList()));
        }
        public async Task <IActionResult> Edit([FromBody] LessonInfo item)
        {
            var lessonInfo = await dbContext
                             .Course
                             .AsNoTracking()
                             .FirstOrDefaultAsync(i => i.Id == item.Id);

            if (lessonInfo != null)
            {
                await Task.Run(() => dbContext.Course.Update(lessonInfo));

                await Task.Run(() => dbContext.SaveChanges());

                return(Ok());
            }

            return(BadRequest(new { message = "Can't edit lesson info" }));
        }
        public LessonSettingsPage(LessonInfo lessonInfo, List <EventType> eventTypes)
        {
            InitializeComponent();
            Title = lessonInfo.Lesson.FullName;

            this.lessonInfo          = lessonInfo;
            updatingProgrammatically = true;
            ShowLesson.IsChecked     = lessonInfo.Settings.Hiding.ShowLesson;
            LessonNotes.Text         = lessonInfo.Notes;
            updatingProgrammatically = false;

            this.eventTypes = eventTypes
                              .Select(et => new CheckedEventType
            {
                EventType = et
            })
                              .OrderBy(et => et.EventType.ShortName)
                              .ToList();
            LessonsEventTypes.ItemsSource = this.eventTypes;
            UpdateEventTypesCheck();
        }
Esempio n. 15
0
        public async Task <ActionResult> Authenticate([FromBody] Driver loginParam)
        {
            var    upperUserName = loginParam.UserName.ToUpper();
            Driver driver        = _context.Drivers
                                   .FirstOrDefault(x => x.UserName.ToUpper().Equals(upperUserName));

            if (driver != null)
            {
                if (driver.Pin == loginParam.Pin)
                {
                    DriverInfo driverInfo = new DriverInfo()
                    {
                        DriverID  = driver.DriverID,
                        FirstName = driver.FirstName,
                        LastName  = driver.LastName,
                        UserName  = driver.UserName,
                        Pin       = driver.Pin,
                        IsActive  = driver.IsActive,
                        GroupID   = driver.GroupID,
                        Group     = driver.Group,
                        ProductID = driver.ProductID,
                    };

                    var lessons = _context.Lessons
                                  .Include(x => x.Attempts)
                                  .AsNoTracking()
                                  .Where(x => x.ProductID == driver.ProductID)
                                  .OrderBy(x => x.LessonOrder);

                    var lessonInfoList = new List <LessonInfo>();
                    foreach (Lesson lesson in lessons)
                    {
                        LessonInfo lessonInfo = new LessonInfo()
                        {
                            LessonID    = lesson.LessonID,
                            PackType    = lesson.PackType,
                            PackID      = lesson.PackID,
                            IsActive    = lesson.IsActive,
                            Name        = lesson.Name,
                            LessonOrder = lesson.LessonOrder
                        };

                        var highScoreAttempt = lesson.Attempts.Where(x => x.DriverID == driver.DriverID).OrderByDescending(x => x.Score).FirstOrDefault();
                        if (highScoreAttempt != null)
                        {
                            lessonInfo.Attempt = new HighScoreAttempt()
                            {
                                AttemptID            = highScoreAttempt.AttemptID,
                                CumulativeLessonTime = highScoreAttempt.CumulativeLessonTime,
                                DateCompleted        = highScoreAttempt.DateCompleted,
                                IsComplete           = highScoreAttempt.IsComplete,
                                Score          = highScoreAttempt.Score,
                                TimeToComplete = highScoreAttempt.TimeToComplete,
                            };
                        }

                        lessonInfoList.Add(lessonInfo);
                    }

                    driverInfo.Lessons = lessonInfoList;

                    return(Ok(driverInfo));
                }

                return(Unauthorized());
            }

            return(NotFound());
        }
        public void IndividualTasksCorrect()
        {
            var groups = new[] { "1", "2" };
            var scheduleUpdaterMock  = new Mock <IScheduleUpdater>();
            var selectionUpdaterMock = new Mock <IStudentSelectionUpdater>();

            var lessonInfo1 = new LessonInfo
            {
                Subject = "l1",
                Group   = "g1"
            };

            var lessonInfo2 = new LessonInfo
            {
                Subject = "l2",
                Group   = "g2"
            };
            var lessonInfo3 = new LessonInfo
            {
                Subject = "l3",
                Group   = "g1"
            };

            scheduleUpdaterMock.Setup(x => x.UpdateSchedule(It.Is <string[]>(s => s == groups)))
            .Returns(new[]
            {
                lessonInfo1,
                lessonInfo2,
                lessonInfo3
            });

            var studentSelection1 = new StudentSelection
            {
                Group          = "g1",
                Name           = "name",
                SpecCourseName = lessonInfo3.Subject
            };
            var studentSelection2 = new StudentSelection
            {
                Group          = studentSelection1.Group,
                Name           = studentSelection1.Name,
                SpecCourseName = lessonInfo1.Subject
            };

            selectionUpdaterMock.Setup(x => x.Update())
            .Returns(new List <StudentSelection>
            {
                studentSelection1,
                studentSelection2
            });

            var individualScheduleBuilder = new IndividualScheduleBuilder(scheduleUpdaterMock.Object, selectionUpdaterMock.Object);
            var updateIndividualSchedule  = individualScheduleBuilder.UpdateIndividualSchedule(groups);

            Assert.That(updateIndividualSchedule.StudentsLessons.Count, Is.EqualTo(1));
            Assert.That(updateIndividualSchedule.StudentsLessons, Contains.Key(studentSelection1.Name));
            Assert.That(updateIndividualSchedule.StudentsLessons.First().Value.Lessons, Contains.Item(lessonInfo1));
            Assert.That(updateIndividualSchedule.StudentsLessons.First().Value.Lessons, Contains.Item(lessonInfo3));

            Assert.That(updateIndividualSchedule.GroupsLessons, Does.Not.ContainKey(lessonInfo1.Group));
            Assert.That(updateIndividualSchedule.GroupsLessons, Contains.Key(lessonInfo2.Group));

            Assert.That(updateIndividualSchedule.GroupsLessons.Count, Is.EqualTo(1));

            CollectionAssert.AreEquivalent(new[] { lessonInfo2 }, updateIndividualSchedule.GroupsLessons[lessonInfo2.Group]);
        }
Esempio n. 17
0
        public static List <TimetableInfo> GetTimetableFromCist(DateTime dateStart, DateTime dateEnd, params Group[] groups)
        {
            List <Group> groupsAllowed = groups.ToList(); //SettingsDataStore.CheckCistTimetableUpdateRights(groups);

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.GetEncoding("Windows-1251");
                try
                {
                    List <TimetableInfo> timetables = new List <TimetableInfo>(); //GetTimetableLocal(groupsAllowed.ToArray());

                    // Getting events
                    Uri    uri  = new Uri(Urls.CistGroupTimetableUrl(Urls.CistTimetableFormat.Csv, dateStart, dateEnd, groupsAllowed.Select(g => g.ID).ToArray()));
                    string data = client.DownloadString(uri);
                    Dictionary <string, List <Event> > newEvents = ParseCistCsvTimetable(data, groupsAllowed.Count > 1);
                    if (newEvents == null)
                    {
                        // Parsing error
                        return(null);
                    }

                    // Updating events and adding new timetables
                    foreach (var group in groupsAllowed)
                    {
                        var groupEvents = new List <Event>();
                        if (newEvents.Keys.Contains(group.Name))
                        {
                            groupEvents = newEvents[group.Name];
                        }
                        else if (groupsAllowed.Count == 1 && newEvents.Count == 1)
                        {
                            groupEvents = newEvents.Values.First();
                        }
                        TimetableInfo groupTimetable = timetables.FirstOrDefault(tt => tt.Group.ID == group.ID);
                        if (groupTimetable == null)
                        {
                            groupTimetable = new TimetableInfo(group);
                            timetables.Add(groupTimetable);
                        }
                        groupTimetable.Events = groupEvents;
                    }

                    // Updating lesson info if needed
                    List <Group> groupsLessonInfoAllowed = groupsAllowed; //SettingsDataStore.CheckCistLessonsInfoUpdateRights(groupsAllowed.ToArray());
                    if (groupsLessonInfoAllowed.Count > 0)
                    {
                        uri  = new Uri(Urls.CistGroupTimetableUrl(Urls.CistTimetableFormat.Xls, DateTime.Now, dateEnd, groupsLessonInfoAllowed.Select(g => g.ID).ToArray()));
                        data = client.DownloadString(uri);
                        Dictionary <string, List <LessonInfo> > groupsLessons = ParseCistXlsLessonInfo(data, groupsLessonInfoAllowed.ToArray());
                        if (groupsLessons != null)
                        {
                            foreach (var group in groupsLessonInfoAllowed)
                            {
                                TimetableInfo timetable = timetables.First(tt => tt.Group.ID == group.ID);
                                // Updating lesson info excluding lesson settings
                                foreach (var newLessonInfo in groupsLessons[group.Name])
                                {
                                    LessonInfo oldLessonInfo = timetable.LessonsInfo.FirstOrDefault(li => li.ShortName == newLessonInfo.ShortName);
                                    if (oldLessonInfo == null)
                                    {
                                        oldLessonInfo = new LessonInfo();
                                        timetable.LessonsInfo.Add(oldLessonInfo);
                                    }
                                    oldLessonInfo.ShortName      = newLessonInfo.ShortName;
                                    oldLessonInfo.LongName       = newLessonInfo.LongName;
                                    oldLessonInfo.EventTypesInfo = newLessonInfo.EventTypesInfo;
                                    oldLessonInfo.LastUpdated    = DateTime.Now;
                                }
                            }
                        }
                    }

                    // Updating LastUpdated for saved groups
                    //List<SavedGroup> AllSavedGroups = GroupsDataStore.GetSaved();
                    //foreach (var group in AllSavedGroups)
                    //{
                    //    if (groupsAllowed.Exists(g => g.ID == group.ID))
                    //    {
                    //        group.LastUpdated = DateTime.Now;
                    //    }
                    //}
                    //GroupsDataStore.UpdateSaved(AllSavedGroups);

                    // Saving timetables
                    //foreach (var newTimetable in timetables)
                    //{
                    //    UpdateTimetableLocal(newTimetable);
                    //    MessagingCenter.Send(Application.Current, MessageTypes.TimetableUpdated, newTimetable.Group.ID);
                    //}

                    return(timetables);
                }
                catch (Exception)
                {
                    //ExceptionService.LogException(ex);
                }
            }
            return(null);
        }
Esempio n. 18
0
        public static Dictionary <string, List <LessonInfo> > ParseCistXlsLessonInfo(string cistXlsTimetableData, params Group[] searchGroups)
        {
            var groupsLessons = new Dictionary <string, List <LessonInfo> >();

            if (searchGroups == null || searchGroups.Length == 0)
            {
                return(groupsLessons);
            }

            try
            {
                // Setting default values
                foreach (string searchGroup in searchGroups.Select(sg => sg.Name))
                {
                    if (string.IsNullOrEmpty(searchGroup))
                    {
                        throw new ArgumentNullException("Group name must be specified");
                    }
                    groupsLessons.Add(searchGroup, new List <LessonInfo>());
                }

                cistXlsTimetableData = cistXlsTimetableData.Substring(cistXlsTimetableData.IndexOf("\n\n"));
                List <string> timetableInfoRaw = cistXlsTimetableData
                                                 .Split(new string[] { @"ss:Type=""String"">" }, StringSplitOptions.RemoveEmptyEntries)
                                                 .Skip(1)
                                                 .ToList();

                for (int i = 0; i < timetableInfoRaw.Count; i += 2)
                {
                    List <string> infoRaw = timetableInfoRaw[i + 1]
                                            .Remove(timetableInfoRaw[i + 1].IndexOf("</Data>"))
                                            .Split(new string[] { ": ", "\n" }, StringSplitOptions.RemoveEmptyEntries)
                                            .ToList();

                    string lessonShortName = timetableInfoRaw[i].Remove(timetableInfoRaw[i].IndexOf("</Data>"));
                    string lessonLongName  = infoRaw[0].Trim();
                    foreach (string groupName in groupsLessons.Keys)
                    {
                        groupsLessons[groupName].Add(new LessonInfo
                        {
                            ShortName = lessonShortName,
                            LongName  = lessonLongName
                        });
                    }

                    foreach (string eventTypeInfoRaw in infoRaw.Skip(1))
                    {
                        List <string> eventTypeInfo = eventTypeInfoRaw.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        if (eventTypeInfo.Count <= 4)
                        {
                            // Event type doesn`t have teacher
                            continue;
                        }

                        // Checking for groups with spaces
                        while (!eventTypeInfo[3].EndsWith(",") && eventTypeInfo.Count > 3)
                        {
                            eventTypeInfo[3] += $" {eventTypeInfo[4]}";
                            eventTypeInfo.RemoveAt(4);
                        }

                        foreach (string groupName in groupsLessons.Keys)
                        {
                            if (!IsGroupsListFromXlsContains(eventTypeInfo[3], groupName))
                            {
                                // Teachers for different groups
                                continue;
                            }
                            LessonInfo lessonInfo = groupsLessons[groupName].First(li => li.ShortName == lessonShortName);

                            string type    = eventTypeInfo[0];
                            string teacher = $"{eventTypeInfo[4]} {eventTypeInfo[5]}{eventTypeInfo[6]}".TrimEnd(',');

                            EventTypeInfo eventType = lessonInfo.EventTypesInfo.FirstOrDefault(et => et.Name == type);
                            if (eventType == null)
                            {
                                eventType = new EventTypeInfo
                                {
                                    Name = type
                                };
                                lessonInfo.EventTypesInfo.Add(eventType);
                            }
                            if (!eventType.Teachers.Contains(teacher))
                            {
                                eventType.Teachers.Add(teacher);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Device.BeginInvokeOnMainThread(() =>
                //{
                //    MessagingCenter.Send(Application.Current, MessageTypes.ExceptionOccurred, ex);
                //});
                groupsLessons = null;
            }
            return(groupsLessons);
        }