Esempio n. 1
0
        public object Put([FromBody] RoofModel model)
        {
            var output = new ResponseDetail();

            try
            {
                if (ModelState.IsValid)
                {
                    var roof = Mapper.Map <Roof>(model);
                    _roofService.UpdateRoof(roof);
                    output.Success = true;
                    output.Message = "Roof Updated Successfully";
                    return(output);
                }
                output.Success = false;
                output.Message = "Something went wrong";
                return(output);
            }
            catch (Exception ex)
            {
                output.Success = false;
                output.Message = ex.Message;
                return(output);
            }
        }
 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);
     }
 }