public async Task <IActionResult> Index(string accountId, string accountLegalEntityId) { var legalEntities = await _legalEntitiesService.Get(accountId); var selectedLegalEntity = legalEntities.FirstOrDefault(x => x.AccountLegalEntityId == accountLegalEntityId); var applicationsResponse = await _applicationService.GetList(accountId, accountLegalEntityId); var model = new HubPageViewModel(_externalLinksConfiguration.ManageApprenticeshipSiteUrl, accountId) { AccountLegalEntityId = accountLegalEntityId, OrganisationName = selectedLegalEntity?.Name, HasMultipleLegalEntities = legalEntities.Count() > 1 }; if (applicationsResponse.ApprenticeApplications.Any()) { model.ShowBankDetailsRequired = BankDetailsRequired(applicationsResponse); model.ShowAmendBankDetails = CanAmendBankDetails(applicationsResponse); model.BankDetailsApplicationId = applicationsResponse.FirstSubmittedApplicationId.Value; model.ShowAcceptNewEmployerAgreement = applicationsResponse.ApprenticeApplications.Any(a => (a.FirstPaymentStatus != null && a.FirstPaymentStatus.RequiresNewEmployerAgreement) || (a.SecondPaymentStatus != null && a.SecondPaymentStatus.RequiresNewEmployerAgreement)); } return(View(model)); }
public void FailedCallToProductCatalogRepository_ShowsAlert() { var alertCalled = false; var productCatalogRepository = new MockProductCatalogRepository(); var navService = new MockNavigationService(); productCatalogRepository.GetRootCategoriesAsyncDelegate = (maxAmmountOfProducts) => { throw new Exception(); }; var alertMessageService = new MockAlertMessageService(); alertMessageService.ShowAsyncDelegate = (s, s1) => { alertCalled = true; Assert.AreEqual("ErrorServiceUnreachable", s1); return(Task.FromResult(string.Empty)); }; var target = new HubPageViewModel(productCatalogRepository, navService, alertMessageService, new MockResourceLoader()); target.OnNavigatedTo(null, NavigationMode.New, null); Assert.IsTrue(alertCalled); }
public void OnNavigatedTo_Fill_RootCategories() { var repository = new MockProductCatalogRepository(); var navigationService = new MockNavigationService(); repository.GetRootCategoriesAsyncDelegate = (maxAmmountOfProducts) => { var categories = new Collection <Category>(new List <Category> { new Category(), new Category(), new Category() }); return(Task.FromResult((ICollection <Category>)categories)); }; var viewModel = new HubPageViewModel(repository, navigationService, null, null); viewModel.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, null); Assert.IsNotNull(viewModel.RootCategories); Assert.AreEqual(((ICollection <CategoryViewModel>)viewModel.RootCategories).Count, 3); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { // restore state from previous session if (e.PageState != null && e.PageState.ContainsKey("HubPageViewModel")) { _viewModel = e.PageState["HubPageViewModel"] as HubPageViewModel; return; } await _viewModel.SignIn(); }
public HubPage() { InitializeComponent(); _viewModel = DataContext as HubPageViewModel; // Hub is only supported in Portrait orientation DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; NavigationCacheMode = NavigationCacheMode.Required; _navigationHelper = new NavigationHelper(this); _navigationHelper.LoadState += NavigationHelper_LoadState; _navigationHelper.SaveState += NavigationHelper_SaveState; }
void dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) { #region lame HttpResponseMessage response = hubService.GetResponse(Global.prijavljeniKorisnik.Id.ToString()); HubPageViewModel model = new HubPageViewModel(); if (response.IsSuccessStatusCode) { model = new HubPageViewModel(response.Content.ReadAsAsync <HubPageViewModel>().Result); defaultViewModel["BookShelves"] = model.BookShelves; } #endregion }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { // TODO: Create an appropriate data model for your problem domain to replace the sample data HttpResponseMessage response = hubService.GetResponse(Global.prijavljeniKorisnik.Id.ToString()); HubPageViewModel model = new HubPageViewModel(); if (response.IsSuccessStatusCode) { model = new HubPageViewModel(response.Content.ReadAsAsync <HubPageViewModel>().Result); } else { MessageDialog msg = new MessageDialog("gresksa"); await msg.ShowAsync(); } defaultViewModel["Feed"] = model.Feed; defaultViewModel["BookShelves"] = model.BookShelves; defaultViewModel["Profile"] = model.Profile; defaultViewModel["Recommendations"] = model.Recommendations; }
public HubPageViewModel GetHubData(int userid) { HubPageViewModel defaultViewModel = new HubPageViewModel(); defaultViewModel.BookShelves = new HubPageViewModel.ShelvesInfo(); defaultViewModel.BookShelves.Shelves = db.Policas.Where(x => x.KorisnikID == userid).Select(y => new HubPageViewModel.ShelvesInfo.ShelfInfo { KorisnikID = y.KorisnikID, Naziv = y.Naziv, ShelfID = y.Id, BookCount = y.Knjigas.Count() }).ToList(); defaultViewModel.Profile = new HubPageViewModel.ProfileInfo(); defaultViewModel.Profile = db.Korisnics.Include("Prijateljstvos").Where(x => x.Id == userid).Select(z => new HubPageViewModel.ProfileInfo { KorisnikID = z.Id, username = z.username, Joined = z.created_at, Grad = z.Grad, FriendCount = db.Prijateljstvos.Where(p => p.Korisnik1ID == userid).Count(), Email = z.Email, ImePrezime = z.Ime + " " + z.Prezime }).FirstOrDefault(); HubPageViewModel.ShelvesInfo.ShelfInfo polica = defaultViewModel.BookShelves.Shelves.Where(x => x.Naziv == "Currently Reading").FirstOrDefault(); if (polica != null) { Polica p = db.Policas.Include("Knjigas").Where(c => c.Id == polica.ShelfID).FirstOrDefault(); List <Knjiga> curb = p.Knjigas; if (curb != null) { defaultViewModel.Profile.CurrentlyReadingBooks = new List <HubPageViewModel.ProfileInfo.BookInfo>(); defaultViewModel.Profile.CurrentlyReadingBooks = curb.Select(k => new HubPageViewModel.ProfileInfo.BookInfo { Autor = db.Autors.Find(k.AutorId).Ime + " " + db.Autors.Find(k.AutorId).Prezime, KnjigaID = k.Id, Naslov = k.Naslov, Slika = k.Slika }).ToList(); } else { defaultViewModel.Profile.CurrentlyReadingBooks = null; } } Helpers.Preporuka preporuka = new Helpers.Preporuka(); List <KnjigaVM> preporuceneKnjige = preporuka.GetPreporuceneKnjige(userid); defaultViewModel.Recommendations = new HubPageViewModel.RecommendationsInfo(); defaultViewModel.Recommendations.RecommendedBooks = preporuceneKnjige.Select(k => new HubPageViewModel.RecommendationsInfo.BookInfo { Autor = k.NazivAutora, KnjigaID = k.Id, Naslov = k.Naslov, Slika = k.Slika }).ToList(); foreach (var k in defaultViewModel.Recommendations.RecommendedBooks) { Knjiga kk = db.Knjigas.Include("Ocjenas").Where(x => x.Id == k.KnjigaID).FirstOrDefault(); k.ProsjecnaOcjena = (float)kk.Ocjenas.Average(a => a.OcjenaIznos); } List <int> ListaPrijatelja = db.Prijateljstvos.Where(x => x.Korisnik1ID == userid).Select(s => s.Korisnik2ID).ToList(); defaultViewModel.Feed = new HubPageViewModel.FeedInfo(); defaultViewModel.Feed.FeedItems = db.TimelineItems.OrderByDescending(r => r.EventDate).Where(g => ListaPrijatelja.Contains(g.KorisnikID)).Select(t => new HubPageViewModel.FeedInfo.FeedItemInfo { EventDescription = t.Korisnik.username + t.EventDescription + " " + t.Knjiga.Ocjenas.Where(o => o.KnjigaID == t.KnjigaID && o.KorisnikID == t.KorisnikID).FirstOrDefault().OcjenaIznos, FeedItemID = t.Id, Slika = t.Knjiga.Slika, EventInformation = t.Knjiga.Naslov, IsOcjena = t.IsOcjena, Autor = t.EventDate.ToString(), KnjigaID = t.KnjigaID, OcjenaID = t.Knjiga.Ocjenas.Where(o => o.KnjigaID == t.KnjigaID && o.KorisnikID == t.KorisnikID).FirstOrDefault().Id }).ToList(); return(defaultViewModel); }