public StreamDetails() { Pal = new PalCollection(); TroutStreams = new TroutStreamCollection(); Restrictions = new List <RestrictionCollection>(); Lakes = new LakeCollection(); LocalNames = new string[0]; Counties = new CountyModel[0]; }
private StreamDetails CreateStreamDetails(stream s) { var d = new StreamDetails(); d.Id = s.gid; d.Name = s.name; d.LengthMiles = decimal.Round(s.length_mi, 2, MidpointRounding.AwayFromZero); d.HasBrookTrout = s.has_brook_trout; d.HasBrownTrout = s.has_brown_trout; d.HasRainbowTrout = s.has_rainbow_trout; d.HasStockedBrookTrout = s.is_brook_trout_stocked; d.HasStockedRainbowTrout = s.is_rainbow_trout_stocked; d.HasStockedBrownTrout = s.is_brown_trout_stocked; d.CentroidLatitude = decimal.Round(s.centroid_latitude, 5, MidpointRounding.AwayFromZero); // s.centroid_latitude; d.CentroidLongitude = decimal.Round(s.centroid_longitude, 5, MidpointRounding.AwayFromZero); //s.centroid_longitude; var roll = rand.Next(0, Messages.Length - 1); d.AlertMessage = Messages[roll]; d.Counties = s.counties.Select(i => new StreamDetails.CountyModel { Id = i.gid, Name = i.name }).ToArray(); var localNames = s.trout_stream_sections.Select(i => i.section_name).Where(i => i != d.Name).ToList(); if (String.IsNullOrWhiteSpace(s.local_name) == false) { localNames.Add(s.local_name); } d.LocalNames = localNames.ToArray(); if (d.LocalNames.Any()) { var priorAltNames = d.LocalNames.ToArray(); var priorCount = priorAltNames.Count(); // remove substring duplicates. West Beaver Creek vs Beaver Creek // we may want to change this. var x = d.LocalNames.Distinct().Where(name => d.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) < 0 || name.IndexOf(d.Name, StringComparison.OrdinalIgnoreCase) < 0).ToArray(); // if primary name is "unnamed", then remove all alternative names with "unnamed". if (d.Name.IndexOf("Unnamed", StringComparison.OrdinalIgnoreCase) >= 0) { x = x.Where(i => i.IndexOf("Unnamed", StringComparison.OrdinalIgnoreCase) < 0).ToArray(); } d.LocalNames = x; var currentCount = d.LocalNames.Count(); if (currentCount != priorCount) { } } var pal = s.publicly_accessible_land_section2.ToList(); var palCollection = new PalCollection(); palCollection.Sections = pal.Select(pa => new PalSection() { Start = decimal.Round(pa.start, 3, MidpointRounding.AwayFromZero), Stop = decimal.Round(pa.stop, 3, MidpointRounding.AwayFromZero), }).ToList(); palCollection.Id = 0; palCollection.IsFederal = false; palCollection.Name = String.Empty; palCollection.Type = String.Empty; d.Pal = palCollection; var lakeSections = s.lake_sections.ToList(); var lakeCollection = new LakeCollection(); lakeCollection.Sections = lakeSections.Select(l => new LakeSection { Start = decimal.Round(l.start, 3, MidpointRounding.AwayFromZero), //l.start, Stop = decimal.Round(l.stop, 3, MidpointRounding.AwayFromZero), Name = _context.lakes.Single(la => la.gid == l.lake_gid).name, LakeId = l.lake_gid }).ToList(); d.Lakes = lakeCollection; var troutStreamSections = s.trout_stream_sections.ToList(); var troutStream = new TroutStreamCollection(); troutStream.Name = s.name; troutStream.ParentStream = s.gid; troutStream.Sections = troutStreamSections.Select(t => new TroutStreamSection { Start = decimal.Round(t.start, 3, MidpointRounding.AwayFromZero), //t.start, Stop = decimal.Round(t.stop, 3, MidpointRounding.AwayFromZero), //t.stop }).ToList(); d.TroutStreams = troutStream; d.Restrictions = GetRestrictionSections(s).ToList(); return(d); }