/// <summary> /// Gets the Location association from the loaded locationAssociations. /// It uses the DataCategory.LocationLatitude and DataCategory.LocationLongitude to find the location. /// </summary> /// <param name="locationAssociations">The loaded location associations.</param> /// <param name="importRow">The row's categories/values.</param> /// <returns></returns> private static Location GetLocationAssociation(IEnumerable<Location> locationAssociations, ImportRow importRow) { Location associatedLocation = null; var locationLatitude = importRow.GetCell(DataCategory.LocationLatitude); var locationLongitude = importRow.GetCell(DataCategory.LocationLongitude); if (locationLatitude == null) throw ImportRowTools.Exception("Latitude not set", importRow); if (locationLongitude == null) throw ImportRowTools.Exception("Longitude not set", importRow); associatedLocation = //compare first 6 decimals locationAssociations.FirstOrDefault( c => ToSixDecimals(c.Latitude.ToString()) == ToSixDecimals(locationLatitude.Value) && ToSixDecimals(c.Longitude.ToString()) == ToSixDecimals(locationLongitude.Value)); if (associatedLocation == null) throw ImportRowTools.Exception( String.Format("Could not find Location with latitude '{0}', longitude '{1}'", locationLatitude, locationLongitude), importRow); return associatedLocation; }
/// <summary> /// Gets the Region association from the loaded regionAssociations and a row's Categories/Associations (if there is one). /// It used the DataCategory.RegionName to find the Region. /// </summary> /// <param name="regionAssociations">The loaded region associations</param> /// <param name="row">The row's categories/values.</param> private static Region GetRegionAssociation(IEnumerable<Region> regionAssociations, ImportRow row) { var regionNameCell = row.GetCell(DataCategory.RegionName); if (regionNameCell == null || string.IsNullOrEmpty(regionNameCell.Value)) return null; var region = regionAssociations.First(ca => ca.Name == regionNameCell.Value); return region; }
/// <summary> /// Gets the Client association from the loaded clientAssociations and a row's Categories/Associations (if there is one). /// It used the DataCategory.ClientName to find the Client. /// </summary> /// <param name="clientAssociations">The loaded clientAssociations</param> /// <param name="row">The row's categories/values.</param> private static Client GetClientAssociation(IEnumerable<Client> clientAssociations, ImportRow row) { //Get the client association var clientNameCell = row.GetCell(DataCategory.ClientName); if (clientNameCell == null) throw ImportRowTools.Exception("Client not set", row); var associatedClient = clientAssociations.FirstOrDefault(ca => ca.Name == clientNameCell.Value); if (associatedClient == null) throw ImportRowTools.Exception(String.Format("Could not find Client '{0}'", clientNameCell.Value), row); return associatedClient; }