public ProfilePageView( UserStatisticsView userStatistics, ObservableCollection <StudiedSetView> usedSets, ObservableCollection <StudiedWordView> studiedWords, ObservableCollection <CreatedSetDto> createdSets) { Statistics = userStatistics; UsedSets = usedSets; StudiedWords = studiedWords; CreatedSets = createdSets; UpdIconPath = Path.GetFullPath("Resources/update_icon.png"); }
private void UpdatePage() { var studiedSetDtos = CatLangRestClient.GetStudiedSets(); var studiedsSetsInfo = studiedSetDtos .Select(s => CatLangRestClient.GetSetById(s.SetId)) .ToList(); var studiedSets = new ObservableCollection <StudiedSetView>( studiedSetDtos .Select(s => new StudiedSetView( studiedsSetsInfo.Single(i => i.Id == s.SetId).StudyTopic, studiedsSetsInfo.Single(i => i.Id == s.SetId).AuthorName, s.IsStudied ? "Изучено" : "Не изучено", s.AttemptsCount.ToString(), s.CorrectAnswers + " из " + s.AnswersCount)) .ToList()); var studiedWordsDtos = CatLangRestClient.GetStudiedWords(); studiedWords = studiedWordsDtos .Select(w => new StudiedWordView( w.Word, w.RiskFactor + "%", w.CorrectAnswers, w.IncorrectAnswers, w.LastAppearanceDate.Date.ToShortDateString(), GetWordsStudyStatus(w.Status))) .OrderBy(w => w.Word.Original) .ToList(); var viewStudiedWords = new ObservableCollection <StudiedWordView>(studiedWords); var createdSets = CatLangRestClient.GetCreatedSets(); var createdSetsView = new ObservableCollection <CreatedSetDto>(createdSets); var averageComplexity = studiedsSetsInfo.Count == 0 ? 0 : Math.Round(studiedsSetsInfo.Sum(s => s.Complexity) / studiedsSetsInfo.Count, 2); var averageAttemptsCount = studiedSetDtos.Count == 0 ? 0 : Math.Round((double)studiedSetDtos.Sum(s => s.AttemptsCount) / studiedSetDtos.Count, 2); var statistics = new UserStatisticsView( createdSets.Count, averageComplexity, studiedWords.Count, studiedSets.Count, averageAttemptsCount); view = new ProfilePageView(statistics, studiedSets, viewStudiedWords, createdSetsView); DataContext = view; FilterStudiedWords(); }