public static int ToAddressHash(this ApprenticeshipLocation location) { var propertiesToHash = new List <string> { location.Name }; if (location.National.HasValue) { propertiesToHash.Add($"{location.National}"); } if (location.Regions != null && location.Regions.Length > 0) { propertiesToHash.Add(string.Join(",", location.Regions)); } if (location.Address != null) { propertiesToHash.Add($"{location.Address?.Latitude}"); propertiesToHash.Add($"{location.Address?.Longitude}"); propertiesToHash.Add($"{location.Address?.Postcode}"); } return(GenerateHash(string.Join(", ", propertiesToHash))); }
public void VenueCorrector_WithCorrections_SetsVenueIdAndAudit() { // Arrange var clock = new FixedClock(); var venueCorrector = new VenueCorrector(clock); var venueCorrection = new VenueBuilder().Build(); var locationToFix = new ApprenticeshipLocation { Id = new Guid("30146B96-F1FC-4B16-A046-D6A3B59CF1CE"), VenueId = Guid.Empty, }; var decoy1 = new ApprenticeshipLocation // decoy { Id = new Guid("E08B4EE9-9AA3-41EC-BAF5-7961416E9A82"), VenueId = Guid.Empty, }; var decoy2 = new ApprenticeshipLocation // decoy { Id = new Guid("E129D3CC-D141-49B9-94FC-E472A2F93A56"), VenueId = Guid.Empty, }; var apprenticeshipVenueCorrection = new ApprenticeshipVenueCorrection { Apprenticeship = new Apprenticeship { ApprenticeshipLocations = new List <ApprenticeshipLocation> { decoy1, locationToFix, decoy2, }, }, ApprenticeshipLocationVenueCorrections = new List <ApprenticeshipLocationVenueCorrection> { new ApprenticeshipLocationVenueCorrection { LocationId = locationToFix.Id, VenueCorrection = venueCorrection, } } }; // Act var applyReturnValue = venueCorrector.Apply(apprenticeshipVenueCorrection); // Assert apprenticeshipVenueCorrection.Apprenticeship.ApprenticeshipLocations.Should().BeEquivalentTo(decoy1, locationToFix, decoy2); locationToFix.VenueId.Should().Be(venueCorrection.Id); locationToFix.UpdatedBy.Should().Be("VenueCorrector"); locationToFix.UpdatedDate.Should().Be(clock.UtcNow); decoy1.VenueId.Should().Be(Guid.Empty); decoy1.UpdatedBy.Should().BeNull(); decoy1.UpdatedDate.Should().BeNull(); decoy2.VenueId.Should().Be(Guid.Empty); decoy2.UpdatedBy.Should().BeNull(); decoy2.UpdatedDate.Should().BeNull(); apprenticeshipVenueCorrection.Apprenticeship.UpdatedBy.Should().Be("VenueCorrector"); apprenticeshipVenueCorrection.Apprenticeship.UpdatedDate.Should().Be(clock.UtcNow); applyReturnValue.Should().BeTrue("changes were applied"); }
public List <string> ConvertToApprenticeshipDeliveryModes(ApprenticeshipLocation location) { var validDeliveryModes = location.DeliveryModes .Cast <DeliveryMode>() .Where(m => Enum.IsDefined(typeof(DeliveryMode), m)) .Select(m => (DeliveryMode)m).ToList(); var culledDeliveryModes = location.DeliveryModes.Count - validDeliveryModes.Count; if (culledDeliveryModes > 0) { var evt = new ExceptionTelemetry(); var undefinedModes = string.Join(", ", location.DeliveryModes .Where(m => !Enum.IsDefined(typeof(DeliveryMode), m))); var errorMessage = $"Could not map mode(s) \'{undefinedModes}\' to a matching {nameof(DeliveryMode)}"; Console.WriteLine($"Culling {culledDeliveryModes} delivery modes: {errorMessage}"); evt.Properties.TryAdd("LocationId", $"{location.ToAddressHash()}"); evt.Properties.TryAdd("Message", errorMessage); _telemetryClient.TrackException( new LocationExportException( location.ApprenticeshipLocationId.ToString(), new InvalidCastException(errorMessage))); } return(validDeliveryModes .Select(m => m.ToDescription()) .ToList()); }
public static int ToAddressHash(this ApprenticeshipLocation location) { var propertiesToHash = new List <string> { location.Venue?.VenueName }; if (location.National.HasValue) { propertiesToHash.Add($"{location.National}"); } if (location.SubRegionIds != null && location.SubRegionIds.Count > 0) { propertiesToHash.Add(string.Join(",", location.SubRegionIds)); } if (location.Venue != null) { propertiesToHash.Add($"{location.Venue.Latitude}"); propertiesToHash.Add($"{location.Venue.Longitude}"); propertiesToHash.Add($"{location.Venue.Postcode}"); } return(GenerateHash(string.Join(", ", propertiesToHash))); }
public void TestVenueAnalyser_ValidLocation_ReturnsCorrectAnalysis() { // Arrange var venue = new VenueBuilder().Build(); var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = venue.Id, Address = AddressFromVenue(venue), }; var apprenticeship = new Apprenticeship { Id = new Guid("80D875B3-3A2C-41C0-96D5-39DADB84CF0D"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, new List <Venue> { venue }); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().BeNull(); apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().BeEmpty("the record isn't corrupt"); }
public ViewDeliveryLocationModel(ApprenticeshipLocation apprenticeshipLocation) { RecordStatusName = apprenticeshipLocation.RecordStatu.RecordStatusName; this.ApprenticeshipName = apprenticeshipLocation.Apprenticeship.ApprenticeshipDetails(); this.DeliveryModesChosen = apprenticeshipLocation.DeliveryModes.ToList(); this.LocationName = apprenticeshipLocation.Location.LocationName; this.Radius = apprenticeshipLocation.Radius; }
public static ApprenticeshipLocation ExtractApprenticeshipLocationFromDbReader(SqlDataReader reader) { ApprenticeshipLocation apprenticeshipLocation = new ApprenticeshipLocation(); apprenticeshipLocation.ApprenticeshipLocationId = (int)CheckForDbNull(reader["ApprenticeshipLocationId"], 0); apprenticeshipLocation.LocationId = (int)CheckForDbNull(reader["LocationId"], 0); apprenticeshipLocation.Radius = (int)CheckForDbNull(reader["Radius"], 0); return(apprenticeshipLocation); }
/// <summary> /// Archives the <see cref="ApprenticeshipLocation"/> and also manages status of it's associated <see cref="Apprenticeship"/> /// </summary> /// <param name="apprenticeshipLocation">The <see cref="ApprenticeshipLocation"/> object</param> /// <param name="db">The <see cref="ProviderPortalEntities"/> object</param> public static void Archive(this ApprenticeshipLocation apprenticeshipLocation, ProviderPortalEntities db) { // Check whether apprenticeship status should be changed to pending ChangeApprenticeshipStatusToPending(apprenticeshipLocation, db); apprenticeshipLocation.RecordStatusId = (Int32)Constants.RecordStatus.Archived; apprenticeshipLocation.AddedByApplicationId = (Int32)Constants.Application.Portal; apprenticeshipLocation.ModifiedByUserId = Permission.GetCurrentUserId(); apprenticeshipLocation.ModifiedDateTimeUtc = DateTime.UtcNow; db.Entry(apprenticeshipLocation).State = EntityState.Modified; }
public void AllMatchingModesShouldMapCorrectly(ApprenticeshipLocation location) { // arrange List <string> expected = _validDeliveryModes; // act var actual = _sut.ConvertToApprenticeshipDeliveryModes(location); // assert Assert.ProperSubset <string>(expected.ToHashSet(), actual.ToHashSet()); }
public static CreateApprenticeshipLocation FromModel(ApprenticeshipLocation model) => new CreateApprenticeshipLocation() { ApprenticeshipLocationId = model.ApprenticeshipLocationId, ApprenticeshipLocationType = model.ApprenticeshipLocationType, DeliveryModes = model.DeliveryModes, National = model.National, Radius = model.Radius, SubRegionIds = model.SubRegionIds, VenueId = model.Venue?.VenueId };
/// <summary> /// Deletes the <see cref="ApprenticeshipLocation"/> and also manages status of it's associated <see cref="Apprenticeship"/> /// </summary> /// <param name="apprenticeshipLocation">The <see cref="ApprenticeshipLocation"/> object</param> /// <param name="db">The <see cref="ProviderPortalEntities"/> object</param> public static void Delete(this ApprenticeshipLocation apprenticeshipLocation, ProviderPortalEntities db) { // Check whether apprenticeship status should be changed to pending ChangeApprenticeshipStatusToPending(apprenticeshipLocation, db); foreach (DeliveryMode item in apprenticeshipLocation.DeliveryModes.ToList()) { apprenticeshipLocation.DeliveryModes.Remove(item); } db.Entry(apprenticeshipLocation).State = EntityState.Deleted; }
/// <inheritdoc/> public IReadOnlyList <Venue> GetMatchingVenues(ApprenticeshipLocation location, IReadOnlyCollection <Venue> providersVenues) { // limit fixes to: // * null/empty -- i.e. missing FKs (39k at last count) // * not in provider's venue list -- i.e. belonging to another provider or missing entirely (9 at last count) if (location.VenueId != null && location.VenueId != Guid.Empty && providersVenues.Any(v => v.Id == location.VenueId)) { return(new Venue[] {}); } return(FindMatchingVenues(providersVenues, location)); }
private ApprenticeshipLocationVenueCorrection AnalyseLocation(ApprenticeshipLocation location, IReadOnlyCollection <Venue> providersVenues) { CorruptionType corruptionType; if (providersVenues.Any(v => v.Id == location.VenueId)) { return(null); // valid record, nothing to do } if (location.VenueId == null) { corruptionType = CorruptionType.NullVenueId; } else if (location.VenueId == Guid.Empty) { corruptionType = CorruptionType.EmptyVenueId; } else { corruptionType = CorruptionType.VenueNotInProvidersLiveVenueList; } var matchingVenues = _venueCorrectionFinder.GetMatchingVenues(location, providersVenues); UnfixableLocationVenueReasons?unfixableLocationVenueReason = null; Venue matchingVenue = null; IReadOnlyList <Venue> duplicateVenues = null; if (matchingVenues == null || !matchingVenues.Any()) { unfixableLocationVenueReason = UnfixableLocationVenueReasons.NoMatchingVenue; } else if (matchingVenues.Count() > 1) { unfixableLocationVenueReason = UnfixableLocationVenueReasons.DuplicateMatchingVenues; duplicateVenues = matchingVenues; } else { matchingVenue = matchingVenues.Single(); } return(new ApprenticeshipLocationVenueCorrection { LocationId = location.Id, VenueIdOriginal = location.VenueId, CorruptionType = corruptionType, VenueCorrection = matchingVenue, UnfixableLocationVenueReason = unfixableLocationVenueReason, DuplicateVenues = duplicateVenues, }); }
public void DisplaysTheCorrectPhoneNumber(ApprenticeshipLocation location) { // Arrange var expected = location.Phone; // Act var locationsList = new Dictionary<string, ApprenticeshipLocation>() { { "1234", location } }; var result = _sut.ApprenticeshipLocationsToLocations(1234, locationsList); var actual = result.FirstOrDefault().Phone; // Assert Assert.Equal(expected, actual); }
public static bool Validate(this AddEditDeliveryLocationViewModel model, ProviderPortalEntities db, ModelStateDictionary modelState) { if (model.SelectedDeliveryModes == null || !model.SelectedDeliveryModes.Any()) { modelState.AddModelError("DeliveryModes", AppGlobal.Language.GetText("DeliveryMode_Edit_DeliveryModesMandatory", "The Delivery Mode field is required")); } // Check Whether Location Has Already Been Used For This Apprenticeship ApprenticeshipLocation al = db.ApprenticeshipLocations.FirstOrDefault(x => x.ApprenticeshipId == model.ApprenticeshipId && x.LocationId == model.LocationId && (model.ApprenticeshipLocationId == 0 || x.ApprenticeshipLocationId != model.ApprenticeshipLocationId)); if (al != null) { modelState.AddModelError("LocationId", AppGlobal.Language.GetText("DeliveryLocation_Edit_LocationAlreadyInUse", "The Location supplied is already in use for this apprenticeship")); } return(modelState.IsValid); }
public void TestVenueAnalyser_WithDuplicateVenues_ReturnsCorrectAnalysis() { // Arrange var potentialMatch = new VenueBuilder() .WithLatitude(60) // fixed value to avoid randomly matching .WithLongitude(-1) // fixed value to avoid randomly matching .Build(); var duplicateMatch = VenueCloner.CloneVenue(potentialMatch); var availableVenues = new List <Venue> { new VenueBuilder().Build(), // decoy venue to make sure it doesn't pick the wrong one potentialMatch, duplicateMatch, }; var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = new Guid("F1724123-CCBA-4811-A816-128542299F87"), Address = AddressFromVenue(potentialMatch), }; var apprenticeship = new Apprenticeship { Id = new Guid("4E75B9D5-CC97-42EE-B891-5420F84EBAE9"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, availableVenues); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().Be(null); var apprenticeshipLocationVenueCorrection = apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().ContainSingle().Subject; apprenticeshipLocationVenueCorrection.LocationId.Should().Be(apprenticeshipLocation.Id); apprenticeshipLocationVenueCorrection.VenueIdOriginal.Should().Be(apprenticeshipLocation.VenueId); apprenticeshipLocationVenueCorrection.CorruptionType.Should().Be(CorruptionType.VenueNotInProvidersLiveVenueList); apprenticeshipLocationVenueCorrection.UnfixableLocationVenueReason.Should().Be(UnfixableLocationVenueReasons.DuplicateMatchingVenues); apprenticeshipLocationVenueCorrection.DuplicateVenues.Should().BeEquivalentTo(potentialMatch, duplicateMatch); }
private static int MatchedFieldsCount(Venue venue, ApprenticeshipLocation location) { int matchCounter = 0; FieldMatchCounter(venue.VenueName, location.Name, ref matchCounter); FieldMatchCounter(venue.AddressLine1, location.Address?.Address1, ref matchCounter); FieldMatchCounter(venue.AddressLine2, location.Address?.Address2, ref matchCounter); FieldMatchCounter(venue.Town, location.Address?.Town, ref matchCounter); FieldMatchCounter(venue.County, location.Address?.County, ref matchCounter); FieldMatchCounter(venue.Postcode, location.Address?.Postcode, ref matchCounter); FieldMatchCounter(venue.Latitude, location.Address?.Latitude, ref matchCounter); FieldMatchCounter(venue.Longitude, location.Address?.Longitude, ref matchCounter); FieldMatchCounter(venue.PHONE, location.Address?.Phone, ref matchCounter); FieldMatchCounter(venue.Email, location.Address?.Email, ref matchCounter); FieldMatchCounter(venue.Website, location.Address?.Website, ref matchCounter); return(matchCounter); }
public void FindsMatchingDuplicateVenues() // seen in dev data { var potentialMatch = new VenueBuilder() .WithLatitude(60) // fixed value to avoid randomly matching .WithLongitude(-1) // fixed value to avoid randomly matching .Build(); var duplicateMatch = VenueCloner.CloneVenue(potentialMatch); var availableVenues = new List <Venue> { new VenueBuilder().Build(), // decoy venue to make sure it doesn't pick the wrong one potentialMatch, duplicateMatch, }; var locationVenueName = potentialMatch.VenueName; var locationAddress = new ApprenticeshipLocationAddress { Address1 = potentialMatch.AddressLine1, Address2 = potentialMatch.AddressLine2, Town = potentialMatch.Town, County = potentialMatch.County, Postcode = potentialMatch.Postcode, Latitude = potentialMatch.Latitude, Longitude = potentialMatch.Longitude, Email = potentialMatch.Email, Phone = potentialMatch.PHONE, Website = potentialMatch.Website, }; var location = new ApprenticeshipLocation { VenueId = Guid.Empty, RecordStatus = (int)ApprenticeshipStatus.Live, Name = locationVenueName, Address = locationAddress, }; // act var matchingVenues = new VenueCorrectionFinder().GetMatchingVenues(location, availableVenues); matchingVenues.Should().BeEquivalentTo(duplicateMatch, potentialMatch); }
public ActionResult View(Int32 id) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } ApprenticeshipLocation apprenticeshipLocation = db.ApprenticeshipLocations.FirstOrDefault(x => x.ApprenticeshipLocationId == id); if (apprenticeshipLocation == null || apprenticeshipLocation.Apprenticeship.ProviderId != userContext.ItemId) { return(HttpNotFound()); } ViewDeliveryLocationModel model = new ViewDeliveryLocationModel(apprenticeshipLocation); return(View(model)); }
/// <summary> /// Unarchives the <see cref="ApprenticeshipLocation"/> and also manages status of it's associated <see cref="Apprenticeship"/> /// </summary> /// <param name="apprenticeshipLocation">The <see cref="ApprenticeshipLocation"/> object</param> /// <param name="db">The <see cref="ProviderPortalEntities"/> object</param> public static void Unarchive(this ApprenticeshipLocation apprenticeshipLocation, ProviderPortalEntities db) { // Set the apprenticeship to LIVE if not currently LIVE Apprenticeship apprenticeship = apprenticeshipLocation.Apprenticeship; if (apprenticeship.RecordStatusId != (Int32)Constants.RecordStatus.Live) { apprenticeship.RecordStatusId = (Int32)Constants.RecordStatus.Live; apprenticeship.AddedByApplicationId = (Int32)Constants.Application.Portal; apprenticeship.ModifiedByUserId = Permission.GetCurrentUserId(); apprenticeship.ModifiedDateTimeUtc = DateTime.UtcNow; db.Entry(apprenticeship).State = EntityState.Modified; } apprenticeshipLocation.RecordStatusId = (Int32)Constants.RecordStatus.Live; apprenticeshipLocation.AddedByApplicationId = (Int32)Constants.Application.Portal; apprenticeshipLocation.ModifiedByUserId = Permission.GetCurrentUserId(); apprenticeshipLocation.ModifiedDateTimeUtc = DateTime.UtcNow; db.Entry(apprenticeshipLocation).State = EntityState.Modified; }
/// <summary> /// Checks whether the <see cref="Apprenticeship"/>'s status need to be set to Pending and sets it if required /// </summary> /// <param name="apprenticeshipLocation">The <see cref="ApprenticeshipLocation"/> object</param> /// <param name="db">The <see cref="ProviderPortalEntities"/> object</param> private static void ChangeApprenticeshipStatusToPending(ApprenticeshipLocation apprenticeshipLocation, ProviderPortalEntities db) { // If there are no other LIVE delivery locations for this apprenticeship and the apprenticeship is currently LIVE then set the apprenticeship status to Pending Apprenticeship apprenticeship = apprenticeshipLocation.Apprenticeship; if (apprenticeship.RecordStatusId == (Int32)Constants.RecordStatus.Live) { if ( apprenticeship.ApprenticeshipLocations.Count( x => x.RecordStatusId == (Int32)Constants.RecordStatus.Live && x.ApprenticeshipLocationId != apprenticeshipLocation.ApprenticeshipLocationId) == 0) { apprenticeship.RecordStatusId = (Int32)Constants.RecordStatus.Pending; apprenticeship.AddedByApplicationId = (Int32)Constants.Application.Portal; apprenticeship.ModifiedByUserId = Permission.GetCurrentUserId(); apprenticeship.ModifiedDateTimeUtc = DateTime.UtcNow; db.Entry(apprenticeship).State = EntityState.Modified; } } }
public void TestVenueAnalyser_LocationWithMatchingVenue_ReturnsCorrectAnalysis() { // Arrange var venue = new VenueBuilder().Build(); var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = new Guid("62915572-18E1-4780-849A-6050E78B5008"), Address = AddressFromVenue(venue) }; var apprenticeship = new Apprenticeship { Id = new Guid("80D875B3-3A2C-41C0-96D5-39DADB84CF0D"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, new List <Venue> { venue }); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().BeNull(); var apprenticeshipLocationVenueCorrection = apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().ContainSingle().Subject; apprenticeshipLocationVenueCorrection.LocationId.Should().Be(apprenticeshipLocation.Id); apprenticeshipLocationVenueCorrection.VenueIdOriginal.Should().Be(apprenticeshipLocation.VenueId); apprenticeshipLocationVenueCorrection.CorruptionType.Should().Be(CorruptionType.VenueNotInProvidersLiveVenueList); apprenticeshipLocationVenueCorrection.UnfixableLocationVenueReason.Should().BeNull(); apprenticeshipLocationVenueCorrection.VenueCorrection.Should().Be(venue); }
public ActionResult Archive(Int32 id) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } ApprenticeshipLocation deliveryLocation = db.ApprenticeshipLocations.Find(id); if (deliveryLocation == null || deliveryLocation.Apprenticeship.ProviderId != userContext.ItemId || deliveryLocation.Apprenticeship.RecordStatusId == (Int32)Constants.RecordStatus.Deleted) { return(HttpNotFound()); } deliveryLocation.Archive(db); db.SaveChanges(); ShowGenericSavedMessage(true); return(RedirectToAction("Edit", "Apprenticeship", new { Id = deliveryLocation.ApprenticeshipId })); }
private static void TestVenueMatch(string locationVenueName, ApprenticeshipLocationAddress locationAddress, Guid?originalVenueGuid, Venue potentialMatch, bool expectVenueCorrection, string reason) { var availableVenues = new List <Venue> { new VenueBuilder().Build(), // decoy venue to make sure it doesn't pick the wrong one }; if (potentialMatch != null) { availableVenues.Add(potentialMatch); } availableVenues.Add(new VenueBuilder().Build()); // another decoy venue to make sure it doesn't pick the wrong one var location = new ApprenticeshipLocation { VenueId = originalVenueGuid, RecordStatus = (int)ApprenticeshipStatus.Live, Name = locationVenueName, Address = locationAddress, }; // act var matchingVenues = new VenueCorrectionFinder().GetMatchingVenues(location, availableVenues); // assert if (expectVenueCorrection) { var matchingVenue = matchingVenues.Should().ContainSingle().Subject; matchingVenue.Should().Be(potentialMatch, reason); } else { matchingVenues.Should().BeEmpty(reason); } }
private void UpdateDeliveryModes(AddEditDeliveryLocationViewModel model, ApprenticeshipLocation deliveryLocation) { }
private ApprenticeshipLocation CreateDeliveryLocation(DeliveryOption loc, ApprenticeshipLocationType apprenticeshipLocationType) { List <int> deliveryModes = new List <int>(); ApprenticeshipLocation apprenticeshipLocation = new ApprenticeshipLocation() { Name = loc.LocationName, CreatedDate = DateTime.Now, CreatedBy = User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(), ApprenticeshipLocationType = apprenticeshipLocationType, Id = Guid.NewGuid(), LocationType = LocationType.Venue, RecordStatus = RecordStatus.Live, Regions = loc.Regions, National = loc.National ?? false, UpdatedDate = DateTime.Now, UpdatedBy = User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(), }; if (loc.Venue != null) { apprenticeshipLocation.TribalId = loc.Venue.TribalLocationId ?? null; apprenticeshipLocation.ProviderId = loc.Venue.ProviderID; apprenticeshipLocation.LocationId = loc.Venue.LocationId ?? null; apprenticeshipLocation.VenueId = Guid.Parse(loc.Venue.ID); apprenticeshipLocation.Address = new Address { Address1 = loc.Venue.Address1, Address2 = loc.Venue.Address2, Town = loc.Venue.Town, County = loc.Venue.County, Postcode = loc.Venue.PostCode, Email = loc.Venue.Email, Phone = loc.Venue.Telephone, Website = loc.Venue.Website, Latitude = (double)loc.Venue.Latitude, Longitude = (double)loc.Venue.Longitude }; } if (!string.IsNullOrEmpty(loc.LocationId)) { apprenticeshipLocation.LocationGuidId = new Guid(loc.LocationId); } if (!string.IsNullOrEmpty(loc.Radius)) { apprenticeshipLocation.Radius = Convert.ToInt32(loc.Radius); } if (!string.IsNullOrEmpty(loc.Delivery)) { var delModes = loc.Delivery.Split(","); foreach (var delMode in delModes) { if (delMode.ToLower().Trim() == @WebHelper.GetEnumDescription(ApprenticeShipDeliveryLocation.DayRelease).ToLower()) { deliveryModes.Add((int)ApprenticeShipDeliveryLocation.DayRelease); } if (delMode.ToLower().Trim() == @WebHelper .GetEnumDescription(ApprenticeShipDeliveryLocation.BlockRelease).ToLower()) { deliveryModes.Add((int)ApprenticeShipDeliveryLocation.BlockRelease); } } } if (apprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBasedAndEmployerBased || apprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased) { deliveryModes.Add((int)ApprenticeShipDeliveryLocation.EmployerAddress); } apprenticeshipLocation.DeliveryModes = deliveryModes; return(apprenticeshipLocation); }
private static bool VenueTightMatch(Venue venue, ApprenticeshipLocation location) { return(VenueNameMatches(venue, location) && VenueAddressMatches(venue, location)); }
private static bool VenueAddressMatches(Venue venue, ApprenticeshipLocation location) { return((!string.IsNullOrWhiteSpace(venue.AddressLine1) && venue.AddressLine1 == location.Address?.Address1) && (!string.IsNullOrWhiteSpace(venue.Postcode) && venue.Postcode == location.Address?.Postcode)); }
private static bool VenueNameMatches(Venue venue, ApprenticeshipLocation location) { return(!string.IsNullOrWhiteSpace(venue.VenueName) && venue.VenueName == location.Name); }
private static IReadOnlyList <Venue> FindMatchingVenues(IEnumerable <Venue> venues, ApprenticeshipLocation location) { // Below 10 matching fields we start to get false-positives in production data const int matchThreshold = 10; var matches = venues.Where(v => ( VenueTightMatch(v, location) || VenueNameMatches(v, location) || VenueAddressMatches(v, location) ) && MatchedFieldsCount(v, location) >= matchThreshold ).ToList(); return(matches); }