override protected void OnNavigatedTo(NavigationEventArgs e) { if (isCustomer) { // if we have a customer we need to load a bunch of info var db = new AirContext(); var user = db.Users.Include(dbuser => dbuser.CustInfo) .ThenInclude(custInfo => custInfo.Trips) .ThenInclude(trip => trip.Origin) .Include(user => user.CustInfo) .ThenInclude(custInfo => custInfo.Trips) .ThenInclude(trip => trip.Destination) .Include(user => user.CustInfo) .ThenInclude(custInfo => custInfo.Trips) .ThenInclude(trip => trip.Tickets) .ThenInclude(ticket => ticket.Flight) .ThenInclude(scheduledFlight => scheduledFlight.Flight) .ThenInclude(flight => flight.Origin) .Include(user => user.CustInfo) .ThenInclude(custInfo => custInfo.Trips) .ThenInclude(trip => trip.Tickets) .ThenInclude(ticket => ticket.Flight) .ThenInclude(scheduledFlight => scheduledFlight.Flight) .ThenInclude(flight => flight.Destination) .Single(dbuser => dbuser.UserId == UserSession.userId); CustomerInfo customerInfo = user.CustInfo; // award points for any trips that have departed & were not yet claimed int newPoints = 0; // loop through all of their trips foreach (Trip trip in customerInfo.Trips) { // check if the trip has departed if (trip.GetFormattedDeparted() == "Trip has departed!") { // make sure they haven't claimed the points already if (!trip.PointsClaimed) { // Award the appropriate points to the user UserUtilities.AwardPoints(user, (trip.TotalCost / 100) * 10); newPoints = trip.TotalCost / 100; // keep track of this for the ui trip.PointsClaimed = true; // set the points claimed to true var dbtrip = db.Trips.Single(dbtripinterior => dbtripinterior.TripId == trip.TripId); dbtrip.PointsClaimed = true; // and update the db as well db.SaveChanges(); } } } // Display basic info about the user WelcomeText.Text = $"Welcome back {customerInfo.Name}!"; PointsText.Text = $"You currently have {customerInfo.PointsAvailable + newPoints} points available, and overall you have used {customerInfo.PointsUsed} points."; CreditText.Text = $"You currently have a credit balance of ${customerInfo.CreditBalance / 100} with us."; TicketSummaryText.Text = $"You have booked {customerInfo.Trips.ToArray().Length} trips with us."; // and fill our list view with the customers trips TripList.ItemsSource = customerInfo.Trips; } }