/// <summary> /// Validates a location. /// </summary> public static void ValidateLocation(OrgUnit location) { const int maximumNameLength = 256; const int maximumAddress1Length = 50; const int maximumAddress2Length = 50; const int maximumCityLength = 50; const int maximumPostalCodeLength = 35; const int maximumPhoneLength = 15; const int maximumFaxLength = 15; // Validate all location entity members if (location == null) throw new BusinessException(string.Format(CultureInfo.CurrentUICulture, "{0} cannot be null.", Common.Constants.LocationEntityName)); if (String.IsNullOrWhiteSpace(location.Name) || (location.Name.Length > maximumNameLength)) throw new BusinessException("Invalid name length."); if (!String.IsNullOrEmpty(location.Address1) && (location.Address1.Length > maximumAddress1Length)) throw new BusinessException("Invalid address line 1 length."); if (!String.IsNullOrEmpty(location.Address2) && (location.Address2.Length > maximumAddress2Length)) throw new BusinessException("Invalid address line 2 length."); if (!String.IsNullOrEmpty(location.City) && (location.City.Length > maximumCityLength)) throw new BusinessException("Invalid city length."); if (!String.IsNullOrEmpty(location.PostalCode) && (location.PostalCode.Length > maximumPostalCodeLength)) throw new BusinessException("Invalid postal code length."); if (!String.IsNullOrEmpty(location.Phone) && (location.Phone.Length > maximumPhoneLength)) throw new BusinessException("Invalid phone number length."); if (!String.IsNullOrEmpty(location.Fax) && (location.Fax.Length > maximumFaxLength)) throw new BusinessException("Invalid fax number length."); }
public void can_add_location() { var subject = new Provider() { Id = 1 }; var orgUnit = new OrgUnit() { Id = 1 }; var providerOrgUnit = subject.AddOrgUnit(orgUnit); Assert.IsNotNull(providerOrgUnit); Assert.AreSame(orgUnit, providerOrgUnit.OrgUnit); Assert.AreSame(subject, providerOrgUnit.Provider); }
public void can_change_primary_location() { var subject = new Provider() { Id = 1 }; var locationA = new OrgUnit() { Id = 1 }; var providerLocationA = subject.AddOrgUnit(locationA); var locationB = new OrgUnit() { Id = 2 }; var providerLocationB = subject.AddOrgUnit(locationB); subject.SetPrimaryOrgUnit(providerLocationB); Assert.IsFalse(providerLocationA.IsPrimary.Value); Assert.IsTrue(providerLocationB.IsPrimary.Value); }
public ProviderOrgUnit(Provider provider, OrgUnit orgUnit) : this() { if (provider == null) { throw new ArgumentNullException("provider"); } if (orgUnit == null) { throw new ArgumentNullException("orgUnit"); } Provider = provider; OrgUnit = orgUnit; }
public void map_Location_to_LocationDto() { var location = new OrgUnit { Id = 1, Description = "test desc", Name = "test", IsEnabled = true, OrgUnitPublished = new OrgUnitPublished() { Id = 1 } }; var dto = Mapper.Map<OrgUnit, OrgUnitDto>(location); Assert.AreEqual(location.Id, dto.Id); }
protected static void LookupCountryId(ObjectContext context, string name, OrgUnit orgUnit) { if (name.IsNullOrWhiteSpace()) return; var item = context.CreateObjectSet<Country>().SingleOrDefault(s => s.Name == name); if (item != null) { orgUnit.CountryId = item.Id; } else { throw new BusinessException(string.Format(CultureInfo.InvariantCulture, "Country with the name of {0} does not exists", name)); } }
/// <summary> /// Finds the CustomURL of the Org Unit or of it's closest parent. /// </summary> /// <param name="context">The context.</param> /// <param name="orgUnit">The org unit.</param> /// <returns></returns> public static string FindOrgUnitUrl(ObjectContext context, OrgUnit orgUnit) { if (orgUnit.OrgUnitTypeAssociations.Any(t => t.OrgUnitType.SiteIndicator) && !string.IsNullOrEmpty(orgUnit.CustomUrl)) return orgUnit.CustomUrl; return context.CreateObjectSet<OrgUnitAssociationPublished>() .Where(o => o.Direction == "Reverse") .Where(o => o.PrimaryId == orgUnit.Id) .Where(o => o.OrgUnitSecondary.CustomUrl != null && o.OrgUnitSecondary.CustomUrl != string.Empty) .Where(o => o.OrgUnitSecondary.OrgUnitTypeAssociations.Any(t => t.OrgUnitType.SiteIndicator)) .Where(o => o.OrgUnitSecondary.IsEnabled) .OrderBy(o => o.Distance) .Select(o => o.OrgUnitSecondary.CustomUrl) .FirstOrDefault(); }
public static void CapturePropertiesForAdd(ObjectContext context, OrgUnitV2 source, OrgUnit target) { target.SetName(source.Name); target.SetAddress1(source.Address1); target.SetAddress2(source.Address2); target.SetCity(source.City); target.SetPostalCode(source.PostalCode); target.SetPhone(source.Phone); target.SetFax(source.Fax); target.SetCustomUrl(source.CustomUrl); target.SetCustomLiveUrl(source.CustomLiveUrl); target.SetCustomStageUrl(source.CustomStageUrl); target.SetCustomQaUrl(source.CustomQaUrl); target.SetCustomDevUrl(source.CustomDevUrl); target.SetServiceLineUrl(source.ServiceLineUrl); target.IsEnabled = source.IsEnabledAsBool.HasValue ? source.IsEnabledAsBool.Value : false; LookupStateId(context, source.State, target); LookupCountryId(context, source.Country, target); target.Latitude = source.LatitudeAsDecimal; target.Longitude = source.LongitudeAsDecimal; int pictureId; if (int.TryParse(source.PictureId, out pictureId)) { target.ImageUrl = source.ImageUrl; target.PictureId = pictureId; } target.Keywords = source.Keywords; target.CustomKeywords = source.CustomKeywords; target.Custom1 = source.Custom1; target.Custom2 = source.Custom2; target.Custom3 = source.Custom3; target.PotentialEventLocation = source.IsPotentialEventLocationAsBool.HasValue ? source.IsPotentialEventLocationAsBool.Value : true; target.SeoPageTitle = source.SeoPageTitle; target.SeoPageDescription = source.SeoPageDescription; target.SeoCustomMetaTags = source.SeoCustomMetaTags; target.SeoH1tag = source.SeoH1Tag; target.SeoPrimaryKeyword = source.SeoPrimaryKeyword; target.SeoSecondaryKeyword = source.SeoSecondaryKeyword; target.SeoCanonicalUrl = source.SeoCanonicalUrl; }
protected static void LookupStateId(ObjectContext context, string stateValue, OrgUnit orgUnit) { if (stateValue.IsNullOrWhiteSpace()) return; var states = context.CreateObjectSet<State>(); var item = states.SingleOrDefault(s => s.Abbreviation == stateValue); if (item == null) item = states.SingleOrDefault(s => s.Name == stateValue); if (item != null) { orgUnit.StateId = item.Id; } else { throw new BusinessException(string.Format(CultureInfo.InvariantCulture, "State with the abbreviation or name of {0} does not exists", stateValue)); } }
public void maps_providerOrgUnit() { var provider = new Provider { Id = 123 }; var orgUnit = new OrgUnit { Id = 1, Description = "test desc", Name = "test", IsEnabled = true }; var providerOrgUnit = new ProviderOrgUnit(provider, orgUnit); var providerOrgUnitDto = Mapper.Map<ProviderOrgUnit, ProviderOrgUnitDto>(providerOrgUnit); Assert.IsNotNull(providerOrgUnitDto); }
public static void AddExternalIdMapping(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit) { if (!string.IsNullOrEmpty(source.OrgUnitExternalId)) { var existingMappings = context.CreateObjectSet<DataImportEntityIdMap>() .Where(m => m.EntityName == "OrgUnit" && m.InternalId == orgUnit.Id) .ToList(); if (existingMappings.Count == 1) { if (existingMappings[0].ExternalId != source.OrgUnitExternalId) { // Update ExternalId on existing mapping existingMappings[0].ExternalId = source.OrgUnitExternalId; } } else { // Remove ambiguous mappings (if any) if (existingMappings.Count > 1) { foreach (var mapping in existingMappings) { context.DeleteObject(mapping); } } // Create new mapping context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap { EntityName = "OrgUnit", DataImportId = 1, InternalId = orgUnit.Id, ExternalId = source.OrgUnitExternalId }); } } }
internal static IEnumerable<ProviderCacheView> AddOrgUnit(this ProviderCacheView provider, OrgUnit orgUnit) { var orgUnitCacheView = new OrgUnitCacheView() { Id = orgUnit.Id, Name = orgUnit.Name, NameUppercase = orgUnit.Name.ToUpperInvariant() }; foreach (var association in orgUnit.OrgUnitTypeAssociations) { var orgUnitTypeCacheView = new OrgUnitTypeCacheView() { Id = association.OrgUnitType.Id, Name = association.OrgUnitType.Name, OrgUnitId = orgUnit.Id, IsOutsideOfOrganization = association.OrgUnitType.IsOutsideOfOrganization }; orgUnitCacheView.OrgUnitTypes.Add(orgUnitTypeCacheView); } var providerOrgUnitCacheView = new ProviderOrgUnitCacheView() { ProviderId = provider.Id, OrgUnitId = orgUnit.Id, OrgUnit = orgUnitCacheView }; provider.ProviderOrgUnits.Add(providerOrgUnitCacheView); return new List<ProviderCacheView>() { provider }; }
private static void BuildKeywordsWithInternalSynonymGenerator(OrgUnit orgUnit, ISettingsManager settingsManager) { var newKeywords = BuildKeywordsWithSynonyms(settingsManager, orgUnit.Keywords, _excludedWords); orgUnit.Keywords = newKeywords; }
private static OrgUnit CreateOrgUnit(int id) { //setup var orgUnitTypeLocations = new OrgUnitType { Id = 1, Name = "Locations", IsEnabled = true, IsOutsideOfOrganization = false }; var orgUnit = new OrgUnit { Id = id, Name = "Hospital A" }; var outa = new List<OrgUnitTypeAssociation> { new OrgUnitTypeAssociation { Id = 1, OrgUnit = orgUnit, OrgUnitType = orgUnitTypeLocations } }; orgUnit.OrgUnitTypeAssociations = outa; return orgUnit; }
/// <summary> /// Uses the specified org unit to fill in missing information for the specified /// published org unit. /// </summary> /// <param name="orgUnit">The org unit.</param> /// <param name="orgUnitPub">The published org unit.</param> /// <param name="disabledOrgUnits">A list of org units determined to be disabled.</param> private static void ApplyOrgUnitInfo(OrgUnit orgUnit, OrgUnitPublished orgUnitPub, Collection<int> disabledOrgUnits) { bool orgUnitPubAddress1Exist = !string.IsNullOrEmpty(orgUnitPub.Address1); // Fill in missing information from specified org unit orgUnitPub.Address1 = ResolveValue(orgUnit.Address1, orgUnitPub.Address1) as string; if (!orgUnitPubAddress1Exist) { orgUnitPub.Address2 = ResolveValue(orgUnit.Address2, orgUnitPub.Address2) as string; } orgUnitPub.City = ResolveValue(orgUnit.City, orgUnitPub.City) as string; orgUnitPub.StateId = ResolveValue(orgUnit.StateId, orgUnitPub.StateId) as int?; orgUnitPub.PostalCode = ResolveValue(orgUnit.PostalCode, orgUnitPub.PostalCode) as string; orgUnitPub.Phone = ResolveValue(orgUnit.Phone, orgUnitPub.Phone) as string; orgUnitPub.Fax = ResolveValue(orgUnit.Fax, orgUnitPub.Fax) as string; orgUnitPub.CountryId = ResolveValue(orgUnit.CountryId, orgUnitPub.CountryId) as int?; orgUnitPub.Metadata = ResolveValue(orgUnit.Metadata, orgUnitPub.Metadata) as string; orgUnitPub.Keyword = ResolveValue(orgUnit.Keyword, orgUnitPub.Keyword) as string; orgUnitPub.CustomFields = ResolveValue(orgUnit.CustomFields, orgUnitPub.CustomFields) as string; orgUnitPub.Latitude = ResolveValue(orgUnit.Latitude, orgUnitPub.Latitude) as decimal?; orgUnitPub.Longitude = ResolveValue(orgUnit.Longitude, orgUnitPub.Longitude) as decimal?; orgUnitPub.Email = ResolveValue(orgUnit.Email, orgUnitPub.Email) as string; orgUnitPub.PaymentProcessorConfigurationId = ResolveValue(orgUnit.PaymentProcessorConfigurationId, orgUnitPub.PaymentProcessorConfigurationId) as int?; // Image and Url information should be published but not inherited. if (orgUnit.Id == orgUnitPub.Id) { orgUnitPub.ImageUrl = ResolveValue(orgUnit.ImageUrl, orgUnitPub.ImageUrl) as string; orgUnitPub.PictureId = ResolveValue(orgUnit.PictureId, orgUnitPub.PictureId) as int?; orgUnitPub.CustomUrl = ResolveValue(orgUnit.CustomUrl, orgUnitPub.CustomUrl) as string; orgUnitPub.CustomLiveUrl = ResolveValue(orgUnit.CustomLiveUrl, orgUnitPub.CustomLiveUrl) as string; orgUnitPub.CustomStageUrl = ResolveValue(orgUnit.CustomStageUrl, orgUnitPub.CustomStageUrl) as string; orgUnitPub.CustomQaUrl = ResolveValue(orgUnit.CustomQaUrl, orgUnitPub.CustomQaUrl) as string; orgUnitPub.CustomDevUrl = ResolveValue(orgUnit.CustomDevUrl, orgUnitPub.CustomDevUrl) as string; orgUnitPub.ServiceLineUrl = ResolveValue(orgUnit.ServiceLineUrl, orgUnitPub.ServiceLineUrl) as string; } if (disabledOrgUnits.Contains(orgUnit.Id)) orgUnitPub.IsEnabled = false; else orgUnitPub.IsEnabled = orgUnitPub.IsEnabled.Value && orgUnit.IsEnabled; if (!orgUnitPub.SchedulesOrgUnitId.HasValue) { if (orgUnit.Schedules.Any()) orgUnitPub.SchedulesOrgUnitId = orgUnit.Id; } if (!orgUnitPub.InsurancesOrgUnitId.HasValue) { if (orgUnit.OrgUnitInsurances.Any()) orgUnitPub.InsurancesOrgUnitId = orgUnit.Id; } // Fill in missing information from specified org unit only if specified org unit is self or linked if (orgUnitPub.Id == orgUnit.Id || orgUnitPub.LinkedOrgUnitId == orgUnit.Id) { if (!orgUnitPub.ServicesOrgUnitId.HasValue) { if (orgUnit.OrgUnitServices.Any()) orgUnitPub.ServicesOrgUnitId = orgUnit.Id; } if (!orgUnitPub.TypesOrgUnitId.HasValue) { if (orgUnit.OrgUnitTypeAssociations.Any()) orgUnitPub.TypesOrgUnitId = orgUnit.Id; } } }
private ProviderOrgUnit CreateProviderOrgUnit() { var provider = new Provider() { Id = 1 }; var orgUnit = new OrgUnit() { Id = 1 }; orgUnit.OrgUnitPublished = new OrgUnitPublished { InsurancesOrgUnit = orgUnit, SchedulesOrgUnit = orgUnit }; return provider.AddOrgUnit(orgUnit); }
/// <summary> /// Resolves all the information for a published org unit entity. /// </summary> /// <param name="orgUnit">The org unit.</param> /// <param name="orgUnitPub">The published org unit.</param> /// <param name="orgUnits">Collection of all org units.</param> /// <param name="orgUnitAssocs">Collection of all org unit associations.</param> /// <param name="disabledOrgUnits">A list of org units determined to be disabled.</param> /// <returns></returns> private static OrgUnitPublished ResolvePublishedOrgUnit(OrgUnit orgUnit, OrgUnitPublished orgUnitPub, OrgUnit[] orgUnits, IEnumerable<OrgUnitAssociation> orgUnitAssocs, Collection<int> disabledOrgUnits) { // Fill in information from org unit (self) ApplyOrgUnitInfo(orgUnit, orgUnitPub, disabledOrgUnits); // Fill in information from linked org unit if (orgUnit.LinkedOrgUnitId != null) { OrgUnit linkedOrgUnit = orgUnits.SingleOrDefault(o => o.Id == orgUnit.LinkedOrgUnitId); ApplyOrgUnitInfo(linkedOrgUnit, orgUnitPub, disabledOrgUnits); } // Repeat process for any ascendants OrgUnitAssociation orgUnitAssoc = orgUnitAssocs.SingleOrDefault(a => a.SecondaryId == orgUnit.Id); int? ascendantId = orgUnitAssoc != null ? orgUnitAssoc.PrimaryId : null; if (ascendantId.HasValue) { OrgUnit ascendantOrgUnit = orgUnits.SingleOrDefault(o => o.Id == ascendantId); ResolvePublishedOrgUnit(ascendantOrgUnit, orgUnitPub, orgUnits, orgUnitAssocs, disabledOrgUnits); } // Ensure schedules/insurances/types/services org unit IDs were set before exiting if (orgUnitPub.SchedulesOrgUnitId == null) orgUnitPub.SchedulesOrgUnitId = orgUnitPub.Id; if (orgUnitPub.InsurancesOrgUnitId == null) orgUnitPub.InsurancesOrgUnitId = orgUnitPub.Id; if (orgUnitPub.TypesOrgUnitId == null) orgUnitPub.TypesOrgUnitId = orgUnitPub.Id; if (orgUnitPub.ServicesOrgUnitId == null) orgUnitPub.ServicesOrgUnitId = orgUnitPub.Id; return orgUnitPub; }
public static void SetOrgUnitTypes(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit) { //ignore null values if (source.OrgUnitTypes == null) return; try { var existingOrgUnitTypes = orgUnit.OrgUnitTypeAssociations.ToArray(); foreach (var item in existingOrgUnitTypes) context.DeleteObject(item); var orgUnitTypes = context.CreateObjectSet<OrgUnitType>(); var orgUnitTypeAssociations = new List<OrgUnitTypeAssociation>(); foreach (var item in source.OrgUnitTypes) { //Ensure orgUnitTypes Exists var orgUnitType = orgUnitTypes.FirstOrDefault(i => i.Name == item.Name); if (orgUnitType == null) { orgUnitType = new OrgUnitType() { Name = item.Name, ImageUrl = item.ImageUrl, IsEnabled = true }; orgUnitTypes.AddObject(orgUnitType); } orgUnitTypeAssociations.Add(new OrgUnitTypeAssociation { OrgUnitType = orgUnitType, OrgUnit = orgUnit, IsPrimaryOrgUnitType = item.IsPrimaryOrgUnitType }); } orgUnit.OrgUnitTypeAssociations = orgUnitTypeAssociations; } catch (Exception ex) { throw new BusinessException("Error processing orgUnitTypes for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex); } }
/// <summary> /// Adds the location. /// </summary> /// <param name="location">The location.</param> /// <returns>A new ProviderOrgUnit instance.</returns> public ProviderOrgUnit AddOrgUnit(OrgUnit location) { if (location == null) { throw new ArgumentNullException("location"); } if (ProviderOrgUnits.Count(pl => pl.OrgUnit.Id.Equals(location.Id)) > 0) { throw new BusinessException("The location is already associated with this provider."); } var providerOrgUnit = new ProviderOrgUnit(this, location); ProviderOrgUnits.Add(providerOrgUnit); if (ProviderOrgUnits.Count == 1) { SetPrimaryOrgUnit(providerOrgUnit); } return providerOrgUnit; }
public void keeps_primary_location_when_adding_new_location() { var subject = new Provider() { Id = 1 }; var locationA = new OrgUnit() { Id = 1 }; var providerLocationA = subject.AddOrgUnit(locationA); var locationB = new OrgUnit(){Id = 2}; var providerLocationB = subject.AddOrgUnit(locationB); Assert.IsTrue(providerLocationA.IsPrimary.Value); Assert.IsFalse(providerLocationB.IsPrimary.HasValue); }
public void can_remove_location() { var subject = new Provider() { Id = 1 }; var firstLocation = new OrgUnit() { Id = 1 }; var secondLocation = new OrgUnit() { Id = 2 }; subject.AddOrgUnit(firstLocation); subject.AddOrgUnit(secondLocation); var removed = subject.RemoveOrgUnit(secondLocation); Assert.AreEqual(secondLocation, removed.OrgUnit); Assert.IsTrue(subject.ProviderOrgUnits.Count == 1); }
public void SetCustomUrl_Valid(string validUrl) { var orgUnit = new OrgUnit(); orgUnit.SetCustomUrl(validUrl); Assert.AreEqual(validUrl, orgUnit.CustomUrl); }
public void SetCustomUrl_Invalid(string invalidUrl) { var orgUnit = new OrgUnit(); orgUnit.SetCustomUrl(invalidUrl); }
public void FilterByOrgUnit() { //setup var orgUnit1 = new OrgUnit { Id = 1 }; var orgUnit2 = new OrgUnit { Id = 2 }; var e = new Event { Id = 1 }; e.EventOccurrences.Add(new EventOccurrence { Id = 1, OrgUnit = orgUnit1 }); _objectSet.Add(e); e = new Event { Id = 2 }; e.EventOccurrences.Add(new EventOccurrence { Id = 2, OrgUnit = orgUnit1 }); e.EventOccurrences.Add(new EventOccurrence { Id = 3, OrgUnit = orgUnit2 }); _objectSet.Add(e); e = new Event { Id = 3 }; e.EventOccurrences.Add(new EventOccurrence { Id = 4, OrgUnit = orgUnit2 }); _objectSet.Add(e); e = new Event { Id = 4 }; _objectSet.Add(e); //act var filtered = _objectSet.AsQueryable().FilterByOrgUnit(1); //assert AssertIncluded(filtered, 1, 2); AssertExcluded(filtered, 3, 4); }
private static OrgUnitDto ConvertToDto(OrgUnit location) { return Mapper.Map<OrgUnitPublished, OrgUnitDto>(location.OrgUnitPublished); }
public void throws_business_exception_when_adding_existing_location() { var subject = new Provider() { Id = 1 }; var location = new OrgUnit() { Id = 1 }; subject.AddOrgUnit(location); subject.AddOrgUnit(location); }
/// <summary> /// Removes the location. /// </summary> /// <param name="location">The location.</param> /// <returns>The removed location.</returns> public ProviderOrgUnit RemoveOrgUnit(OrgUnit location) { if (location == null) { throw new ArgumentNullException("location"); } var providerOrgUnit = ProviderOrgUnits.Single(pl => pl.OrgUnit.Id == location.Id); if (providerOrgUnit.IsPrimary.HasValue && providerOrgUnit.IsPrimary.Value) { throw new BusinessException("Primary Location cannot be removed from the provider."); } ProviderOrgUnits.Remove(providerOrgUnit); return providerOrgUnit; }
public void throws_business_exception_when_removing_primary_location() { var subject = new Provider() { Id = 1 }; var firstLocation = new OrgUnit() { Id = 1 }; var secondLocation = new OrgUnit() { Id = 2 }; subject.AddOrgUnit(firstLocation); subject.AddOrgUnit(secondLocation); subject.RemoveOrgUnit(firstLocation); }
public void makes_first_location_primary() { var subject = new Provider() { Id = 1 }; var location = new OrgUnit() { Id = 1 }; var providerLocation = subject.AddOrgUnit(location); Assert.IsTrue(providerLocation.IsPrimary.Value); }
/// <summary> /// Validates the org unit. /// </summary> /// <param name="orgUnit">The org unit.</param> public static void ValidateOrgUnit(OrgUnit orgUnit) { if (string.IsNullOrEmpty(orgUnit.Name)) { throw new BusinessException("Location Name is missing"); } //Latitude var latitude = orgUnit.Latitude; //null latitude is ok if (latitude.HasValue) { //not null, so verify values are within correct range if (latitude.Value >= 90 || latitude.Value <= -90) throw new BusinessException(orgUnit.Name + " has an invalid latitude"); } //Longitude var longitude = orgUnit.Longitude; //null longitude is ok if (longitude.HasValue) { //not null, so verify values are within correct range if (longitude.Value >= 180 || longitude.Value <= -180) throw new BusinessException(orgUnit.Name + " has an invalid longitude"); } }