public async Task <Result <Model, ValidationError> > Handle(Query message) { var course = await _dbContext.Courses .Include(c => c.Students) .ThenInclude(s => s.Student) .SingleOrDefaultAsync(x => x.Id == message.CourseId); if (course == null) { return(Result.Error <Model> .Create(MissingCourse)); } return(Result.Ok <ValidationError> .Create(new Model { Statistics = await _statisticsService.Get(message.CourseId), Teacher = course.Teacher, Students = course.Students.Select(x => x.Student).ToList() })); }
public IHttpActionResult Get() { var model = _statisticsService.Get(); return(Ok(_mapper.Map <StatisticsDTO>(model))); }
public async Task LoadData() { // load remote data const string genericErrorMessage = "Sorry, an error occurred when retrieving your data. Try again later."; rfsHome.IsRefreshing = true; try { // get the most recent books var bookResponse = await _bookService.GetRecent(); var books = bookResponse.ToList(); if (books.Any()) { lstRecentBooks.ItemsSource = books; lblNoRecentBooks.IsVisible = false; } else { lblNoRecentBooks.IsVisible = true; } // get the top authors var authorResponse = await _authorService.GetTop(); var authors = authorResponse.ToList(); if (authors.Any()) { lstTopAuthors.ItemsSource = authors; lblNoAuthors.IsVisible = false; } else { lblNoAuthors.IsVisible = true; } // get the top publishers var publisherResponse = await _publisherService.GetTop(); var publishers = publisherResponse.ToList(); if (publishers.Any()) { lstTopPublishers.ItemsSource = publishers; lblNoPublishers.IsVisible = false; } else { lblNoPublishers.IsVisible = true; } // get the stats for the books var stats = await _statisticsService.Get(); lblBooksCount.Text = stats.Books.ToString(); lblAuthorsCount.Text = stats.Authors.ToString(); lblPublishersCount.Text = stats.Publishers.ToString(); lblWishlistCount.Text = stats.WishListItems.ToString(); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message : genericErrorMessage); } finally { rfsHome.IsRefreshing = false; } }
public ActionResult Get() { List <Statistics> stats = _statsService.Get(); return(Ok(new { values = stats })); }