public List <ViolationsGroupedByLocationsDTO> GetHistoricalViolationsListGroupedByLocation(DateTime?StartDateTime, DateTime?EndDateTime, int?ViolationTypeId) { try { List <AssetsViewDTO> AssetsList = new AssetsDAL().GetAssetsList(null, null); var lstViolations = stcDataContext.fn_GroupHistoricalViolationsByLocations(StartDateTime, EndDateTime, ViolationTypeId) .Select(Violation => new ViolationsGroupedByLocationsDTO { Altitude = 1, Latitude = Violation.Latitude.Value, Longitude = Violation.Longitude.Value, ViolationsCount = Violation.ViolationsCount, LocationCode = Violation.SerialNumber }).ToList(); foreach (var item in lstViolations) { string serialNumber = item.LocationCode; var asset = AssetsList.Where(a => a.SerialNo == serialNumber).FirstOrDefault(); if (asset == null) { item.LocationCode = ""; continue; } if (item.Latitude == null || item.Latitude == 0) { item.Latitude = asset.Latitude.HasValue ? asset.Latitude.Value : item.Latitude; } if (item.Longitude == null || item.Longitude == 0) { item.Longitude = asset.Longitude.HasValue ? asset.Longitude.Value : item.Longitude; } item.LocationCode = asset.LocationCode; } return(lstViolations); } catch (Exception ex) { } return(null); }