private RecalculatedPropertyModel GetViewModelFromProperty(PropertyModel property, RoofModel roof = null) { try { List <SectionModel> sections = null; if (roof != null) { sections = roof.Sections; } else { sections = _property.Roofs.SelectMany(x => x.Sections).ToList(); } var overallPitch = RoofUtility.GetPredominantPitchFromSections(sections); var count = RoofUtility.GetPitchCount(sections)?.PitchCount ?? 1; var recalc = new RecalculatedPropertyModel(property) { RecalculatedSections = property.Roofs.SelectMany(x => x.Sections).Where(x => x.PitchRise == overallPitch).ToList(), CurrentPitch = overallPitch, OriginalPitch = overallPitch, PitchCount = count }; recalc.Roofs = recalc.Roofs.Where(x => x.Name == (roof?.Name ?? x.Name)).ToList(); return(recalc); } catch (Exception ex) { _logger.LogError("Failed to get view model from property.", ex, property); return(null); } }
private void SetUIMeasurements(int selectedRoofIndex) { try { if (_property == null || _image == null) { return; } // Recalculate roof totals for current property CalculateCurrentTotals(_property); // Materialize view _recalculated = GetViewModelFromProperty(_property, selectedRoofIndex > 0 ? _property.Roofs.FirstOrDefault(x => x.RoofId == (selectedRoofIndex - 1).ToString()) : null); // Set GUI and event handlers var stream = new StreamImageSource(); stream.Stream = (x) => { return(Task.FromResult <Stream>(new MemoryStream(_image.Image))); }; OrderId = $"Order ID: {_order.OrderId}"; PredominantPitch = $"{_recalculated.CurrentPitch}:12"; NumberOfPitches = $"Number of Distinct Pitches Measured: {_recalculated.PitchCount}"; ImageSource = stream; Address = StringUtility.RemoveEmptyLines(_property.Address); Area = $"{Convert.ToInt64(_recalculated.Roofs.Sum(x => x.TotalArea)).ToString()} sq. ft."; Squares = $"Total Squares: {_recalculated.Roofs.Sum(x => x.TotalSquares).ToString()} squares"; } catch (Exception ex) { _logger.LogError($"Failed to set UI to new measurements.", ex); } RefreshTableView(_recalculated.Roofs.Sum(x => x.TotalArea)); }