public ZoneFilter() { Name = "Zone"; InputType = InputType.Select; FilterType = FilterType.Integer; FacetValues = ZoneHelper.GetZones().Select(z => z.Id).ToDictionary(m => m.ToString(), c => (long?)0L); }
public string DisplayValue(string value, long?count = null) { if (int.TryParse(value, out var zoneId)) { if (zoneId > 0) { var zone = ZoneHelper.GetZones().First(z => z.Id == zoneId).Name; return(count != null ? $"{zone} ({count})" : $"{zone}"); } else { return(""); } } else { return(value.ToString()); } }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); Zones = new List <Zone> { new Zone { Id = null, Name = "" } }.Concat(ZoneHelper.GetZones()); ChosenSoilTypes = new List <SoilType>(); if (Id > 0 || PlantInfo != null) { PlantInfo ??= await ApiClient.GetPlantInfoAsync(Id); if (PlantInfo.Photos != null && PlantInfo.Photos.Any()) { UploadedPhotos = PlantInfo.Photos.ToList(); } else { UploadedPhotos = new List <Photo>(); } PlantInfo.SelectedLifeform = PlantInfo.Lifeform; SelectedOrigin = PlantInfo.Origin; MinimumZoneId = PlantInfo.Requirements.ZoneRequirements?.MinimumZone?.Id; MaximumZoneId = PlantInfo.Requirements.ZoneRequirements?.MaximumZone?.Id; ChosenStratificationStages = new LinkedList <StratificationStage>(); if (PlantInfo.Requirements.StratificationStages != null) { PlantInfo.Requirements.StratificationStages.OrderBy(s => s.Step).ToList().ForEach(s => { ChosenStratificationStages.AddLast(s); }); } ChosenWildlifeEffects = new List <WildlifeEffect>(); if (PlantInfo.WildlifeEffects != null) { PlantInfo.WildlifeEffects.ToList().ForEach(we => { ChosenWildlifeEffects.Add(we); }); } ChosenSoilTypes = new List <SoilType>(); if (PlantInfo.SoilTypes != null) { PlantInfo.SoilTypes.ToList().ForEach(s => { ChosenSoilTypes.Add(s); }); } } else { IsEditing = true; ChosenStratificationStages = new LinkedList <StratificationStage>(); ChosenWildlifeEffects = new List <WildlifeEffect>(); ChosenSoilTypes = new List <SoilType>(); PlantInfo = new PlantInfo { Origin = null, Requirements = new Requirements { WaterRequirements = new WaterRequirements(), LightRequirements = new LightRequirements(), ZoneRequirements = new ZoneRequirements { MinimumZone = new Zone(), MaximumZone = new Zone() }, StratificationStages = new List <StratificationStage>() }, BloomTime = new BloomTime(), Spread = new Spread(), Height = new Height(), Photos = new List <Photo>() }; } }
public static Search.Models.PlantInfo AsSearchModel(this Models.PlantInfo source, IEnumerable <Models.PlantLocation> plantLocations, IEnumerable <Models.Synonym> synonyms) { var plantLocationSearch = plantLocations?.Select(pl => pl.AsSearchModel()) ?? source.Locations?.Select(pl => pl.AsSearchModel()); var bloomTimes = new List <Month>(); if (source.BloomTime != null) { if (source.BloomTime.MinimumBloomTime > 0 && source.BloomTime.MaximumBloomTime > 0) { for (var i = source.BloomTime.MinimumBloomTime; i <= source.BloomTime.MaximumBloomTime; i++) { bloomTimes.Add(i); } } else { if (source.BloomTime.MinimumBloomTime > 0) { bloomTimes.Add(source.BloomTime.MinimumBloomTime); } if (source.BloomTime.MaximumBloomTime > 0 && source.BloomTime.MinimumBloomTime != source.BloomTime.MaximumBloomTime) { bloomTimes.Add(source.BloomTime.MaximumBloomTime); } } } var waterTypes = new List <WaterType>(); if (source.Requirements?.WaterRequirements != null) { if (source.Requirements.WaterRequirements.MinimumWater != WaterType.Unknown && source.Requirements.WaterRequirements.MaximumWater != WaterType.Unknown) { var minWater = source.Requirements.WaterRequirements.MinimumWater; var maxWater = source.Requirements.WaterRequirements.MaximumWater; for (var i = minWater; i <= maxWater; i++) { waterTypes.Add(i); } } else { if (source.Requirements.WaterRequirements.MinimumWater != WaterType.Unknown) { waterTypes.Add(source.Requirements.WaterRequirements.MinimumWater); } if (source.Requirements.WaterRequirements.MaximumWater != WaterType.Unknown) { waterTypes.Add(source.Requirements.WaterRequirements.MaximumWater); } } } var lightTypes = new List <LightType>(); if (source.Requirements?.LightRequirements != null) { if (source.Requirements.LightRequirements.MinimumLight != LightType.Unknown && source.Requirements.LightRequirements.MaximumLight != LightType.Unknown) { var minLight = source.Requirements.LightRequirements.MinimumLight; var maxLight = source.Requirements.LightRequirements.MaximumLight; for (var i = minLight; i <= maxLight; i++) { lightTypes.Add(i); } } else { if (source.Requirements.LightRequirements.MinimumLight != LightType.Unknown) { lightTypes.Add(source.Requirements.LightRequirements.MinimumLight); } if (source.Requirements.LightRequirements.MaximumLight != LightType.Unknown) { lightTypes.Add(source.Requirements.LightRequirements.MaximumLight); } } } var zones = new List <Search.Models.Zone>(); var allZones = ZoneHelper.GetZones(); if (source.Requirements?.ZoneRequirements?.MinimumZone != null && source.Requirements?.ZoneRequirements?.MaximumZone != null) { for (var i = source.Requirements?.ZoneRequirements?.MinimumZone.Id; i <= source.Requirements?.ZoneRequirements?.MaximumZone.Id; i++) { zones.Add(allZones.First(z => z.Id == i).AsSearchModel()); } } else { if (source.Requirements?.ZoneRequirements?.MinimumZone != null) { zones.Add(source.Requirements?.ZoneRequirements?.MinimumZone.AsSearchModel()); } if (source.Requirements?.ZoneRequirements?.MaximumZone != null && source.Requirements?.ZoneRequirements?.MinimumZone.Id != source.Requirements?.ZoneRequirements?.MaximumZone.Id) { zones.Add(source.Requirements?.ZoneRequirements?.MaximumZone.AsSearchModel()); } } return(new Search.Models.PlantInfo { Id = source.PlantInfoId, CommonName = source.CommonName, ScientificName = source.ScientificName, Origin = source.Origin?.AsSearchModel(), Lifeform = source.Lifeform.AsSearchModel(), PlantLocations = plantLocationSearch, Synonyms = synonyms?.Select(s => s.AsSearchModel()), MinimumBloomTime = source.BloomTime != null && source.BloomTime?.MinimumBloomTime != Month.Unknown ? (short?)source.BloomTime.MinimumBloomTime : null, MaximumBloomTime = source.BloomTime != null && source.BloomTime?.MaximumBloomTime != Month.Unknown ? (short?)source.BloomTime.MaximumBloomTime : null, BloomTimes = bloomTimes.Any() ? bloomTimes : null, MinimumHeight = source.Height != null ? source.Height?.MinimumHeight : null, MaximumHeight = source.Height != null ? source.Height?.MaximumHeight : null, HeightUnit = source.Height != null && (source.Height.MinimumHeight.HasValue || source.Height.MaximumHeight.HasValue) ? DistanceUnit.Feet : null, MinimumSpread = source.Spread != null ? source.Spread?.MinimumSpread : null, MaximumSpread = source.Spread != null ? source.Spread?.MaximumSpread : null, SpreadUnit = source.Spread != null && (source.Spread.MinimumSpread.HasValue || source.Spread.MaximumSpread.HasValue) ? DistanceUnit.Feet : null, MinimumLight = source.Requirements?.LightRequirements?.MinimumLight != LightType.Unknown ? source.Requirements?.LightRequirements?.MinimumLight : null, MaximumLight = source.Requirements?.LightRequirements?.MaximumLight != LightType.Unknown ? source.Requirements?.LightRequirements?.MaximumLight : null, LightTypes = lightTypes.Any() ? lightTypes : null, MinimumWater = source.Requirements?.WaterRequirements?.MinimumWater != WaterType.Unknown ? source.Requirements?.WaterRequirements?.MinimumWater : null, MaximumWater = source.Requirements?.WaterRequirements?.MaximumWater != WaterType.Unknown ? source.Requirements?.WaterRequirements?.MaximumWater : null, WaterTypes = waterTypes.Any() ? waterTypes : null, MinimumZone = source.Requirements?.ZoneRequirements?.MinimumZone?.AsSearchModel(), MaximumZone = source.Requirements?.ZoneRequirements?.MaximumZone?.AsSearchModel(), Zones = zones.Any() ? zones : null, StratificationStages = source.Requirements?.StratificationStages?.Select(s => s.AsSearchModel()), Preferred = source.Preferred, Taxon = source.Taxon?.AsSearchModel(), WildlifeEffects = source.WildlifeEffects, SoilTypes = source.SoilTypes, Notes = source.Notes, Visibility = source.Visibility, User = source.User?.AsSearchModel(), CreatedBy = source.CreatedBy, ModifiedBy = source.ModifiedBy, DateCreated = source.DateCreated ?? DateTime.UtcNow, DateModified = source.DateModified }); }
public static Search.Models.PlantInfo AsSearchModel(this PlantInfo source, IEnumerable <PlantLocation> plantLocations, IEnumerable <Synonym> synonyms) { var plantLocationSearch = plantLocations?.Select(pl => pl.AsSearchModel()) ?? source.PlantLocations?.Select(pl => pl.AsSearchModel()); var bloomTimes = new List <Month>(); if (source.MinimumBloomTime > 0 && source.MaximumBloomTime > 0) { for (var i = source.MinimumBloomTime; i <= source.MaximumBloomTime; i++) { bloomTimes.Add((Month)i); } } else { if (source.MinimumBloomTime > 0) { bloomTimes.Add((Month)source.MinimumBloomTime); } if (source.MaximumBloomTime > 0 && source.MinimumBloomTime != source.MaximumBloomTime) { bloomTimes.Add((Month)source.MaximumBloomTime); } } var waterTypes = new List <WaterType>(); if (!string.IsNullOrEmpty(source.MinimumWater) && !string.IsNullOrEmpty(source.MaximumWater)) { var minWater = Enum.Parse <WaterType>(source.MinimumWater); var maxWater = Enum.Parse <WaterType>(source.MaximumWater); for (var i = minWater; i <= maxWater; i++) { waterTypes.Add(i); } } else { if (!string.IsNullOrEmpty(source.MinimumWater)) { var minWater = Enum.Parse <WaterType>(source.MinimumWater); waterTypes.Add(minWater); } if (!string.IsNullOrEmpty(source.MaximumWater) && source.MinimumWater != source.MaximumWater) { var maxWater = Enum.Parse <WaterType>(source.MaximumWater); waterTypes.Add(maxWater); } } var lightTypes = new List <LightType>(); if (!string.IsNullOrEmpty(source.MinimumLight) && !string.IsNullOrEmpty(source.MaximumLight)) { var minLight = Enum.Parse <LightType>(source.MinimumLight); var maxLight = Enum.Parse <LightType>(source.MaximumLight); for (var i = minLight; i <= maxLight; i++) { lightTypes.Add(i); } } else { if (!string.IsNullOrEmpty(source.MinimumLight)) { var minLight = Enum.Parse <LightType>(source.MinimumLight); lightTypes.Add(minLight); } if (!string.IsNullOrEmpty(source.MaximumLight) && source.MinimumLight != source.MaximumLight) { var maxLight = Enum.Parse <LightType>(source.MaximumLight); lightTypes.Add(maxLight); } } var zones = new List <Search.Models.Zone>(); var allZones = ZoneHelper.GetZones(); if (source.MinimumZone != null && source.MaximumZone != null) { for (var i = source.MinimumZone.Id; i <= source.MaximumZone.Id; i++) { zones.Add(allZones.First(z => z.Id == i).AsSearchModel()); } } else { if (source.MinimumZone != null) { zones.Add(source.MinimumZone.AsSearchModel()); } if (source.MaximumZone != null && source.MinimumZone.Id != source.MaximumZone.Id) { zones.Add(source.MaximumZone.AsSearchModel()); } } return(new Search.Models.PlantInfo { Id = source.Id, CommonName = source.CommonName, ScientificName = source.ScientificName, Origin = source.Origin?.AsSearchModel(), Lifeform = source.Lifeform.AsSearchModel(), PlantLocations = plantLocationSearch, Synonyms = synonyms?.Select(s => s.AsSearchModel()), MinimumBloomTime = source.MinimumBloomTime, MaximumBloomTime = source.MaximumBloomTime, BloomTimes = bloomTimes.Any() ? bloomTimes : null, MinimumHeight = source.MinimumHeight, MaximumHeight = source.MaximumHeight, HeightUnit = source.MinimumHeight.HasValue || source.MaximumHeight.HasValue ? DistanceUnit.Feet : null, MinimumSpread = source.MinimumSpread, MaximumSpread = source.MaximumSpread, SpreadUnit = source.MinimumSpread.HasValue || source.MaximumSpread.HasValue ? DistanceUnit.Feet : null, MinimumLight = !string.IsNullOrEmpty(source.MinimumLight) ? Enum.Parse <LightType>(source.MinimumLight) : null, MaximumLight = !string.IsNullOrEmpty(source.MaximumLight) ? Enum.Parse <LightType>(source.MaximumLight) : null, LightTypes = lightTypes.Any() ? lightTypes : null, MinimumWater = !string.IsNullOrEmpty(source.MinimumWater) ? Enum.Parse <WaterType>(source.MinimumWater) : null, MaximumWater = !string.IsNullOrEmpty(source.MaximumWater) ? Enum.Parse <WaterType>(source.MaximumWater) : null, WaterTypes = waterTypes.Any() ? waterTypes : null, MinimumZone = source.MinimumZone?.AsSearchModel(), MaximumZone = source.MaximumZone?.AsSearchModel(), Zones = zones.Any() ? zones : null, StratificationStages = source.StratificationStages != null?JsonConvert.DeserializeObject <List <Search.Models.StratificationStage> >(source.StratificationStages) : null, Preferred = source.Preferred, Taxon = source.Taxon?.AsSearchModel(), WildlifeEffects = source.WildlifeEffects != null?JsonConvert.DeserializeObject <List <WildlifeEffect> >(source.WildlifeEffects) : null, SoilTypes = source.SoilTypes != null?JsonConvert.DeserializeObject <List <SoilType> >(source.SoilTypes) : null, Notes = source.Notes, Visibility = source.Visibility, User = source.User?.AsSearchModel(), CreatedBy = source.CreatedBy, ModifiedBy = source.ModifiedBy, DateCreated = source.DateCreated, DateModified = source.DateModified }); }