private void BuildPlantList() { if (AllPlants != null) { if (sortPlantsNow) { double extra; List <PlantViewModel> ToReturn = new List <PlantViewModel>(); foreach (PlantViewModel p in AllPlants) { var ext = p.plant.Extractions.Items.Where(var2 => var2.StartTime >= SelectionStartTime & var2.EndTime <= SelectionEndTime); if (ext.Count() == 0) { extra = 0; } else { extra = ext.Average(var => var.Value); } if (extra >= MinYearlyExtraction) { ToReturn.Add(p); } } SortedAndFilteredPlants = ToReturn.OrderBy(_plantSorter); if (SortedAndFilteredPlants.Count() > 0) { CanSaveExtractions = true; } } else { SortedAndFilteredPlants = AllPlants.OrderBy(_plantSorter); } } RaisePropertyChanged("SortedAndFilteredPlants"); }
void HandleValueChanged(object sender, ValueChangedEventArgs args) { if (args.DatabaseError != null) { Debug.LogError(args.DatabaseError.Message); return; } else { if (args.Snapshot.Value != null) { Debug.Log("Last added items were " + args.Snapshot.GetRawJsonValue().ToString()); json = args.Snapshot.GetRawJsonValue(); allPlants = JsonUtility.FromJson <AllPlants>(json); DatabaseChanges = json; } else { Debug.Log("There are no records in the DB yet!"); } } }
public async Task <IActionResult> OnGet() { var user = await _userManager.Users .AsNoTracking() .Include(x => x.UserPlants) .ThenInclude(x => x.Plant) .ThenInclude(x => x.PlantNames) .SingleAsync(x => x.Id == "natura"); UserPlantCollection = user.PlantCollection; AllPlants = await _db.Plants .AsNoTracking() .Include(x => x.PlantNames) .ToListAsync(); var rnd = new Random(); foreach (var plant in AllPlants.AsParallel()) { if (!string.IsNullOrWhiteSpace(plant.GbifSpeciesKey)) { var images = await _gbifClient.FindImagesForSpecies(plant.GbifSpeciesKey); GbifImage?image = null; if (images.Any()) { var randomIndex = rnd.Next(0, images.Count - 1); image = images.ElementAt(randomIndex); } PlantsWithImages.TryAdd(plant, image); } } return(Page()); }
private static void AddPlant(PlantInfo plant) { AllPlants.Add(plant.Type, plant); }