/// <summary> /// Creates a new address in the system. /// </summary> /// <typeparam name="T">The type that is IAddressable, such as Organization.</typeparam> /// <param name="additionalAddress">The new address.</param> /// <returns>The address entity.</returns> public Address Create <T>(AdditionalAddress <T> additionalAddress) where T : class, IAddressable { var dbSet = Context.Set <T>(); var id = additionalAddress.GetAddressableEntityId(); var entity = dbSet.Find(id); throwIfEntityNotFound(id, entity, typeof(T)); var city = Context.Locations.Find(additionalAddress.CityId); throwIfLocationNotFound(additionalAddress.CityId, city, "City"); var country = Context.Locations.Find(additionalAddress.CountryId); throwIfLocationNotFound(additionalAddress.CountryId, country, "Country"); Location division = null; if (additionalAddress.DivisionId.HasValue) { division = Context.Locations.Find(additionalAddress.DivisionId.Value); throwIfLocationNotFound(additionalAddress.DivisionId.Value, division, "Division"); } var existingAddresses = additionalAddress.CreateGetAddressesQuery(this.Context).ToList(); return(DoCreateAddress <T>( entity: entity, additionalAddress: additionalAddress, existingAddresses: existingAddresses, country: country, division: division, city: city)); }
private Address DoCreateAddress <T>( T entity, AdditionalAddress <T> additionalAddress, ICollection <Address> existingAddresses, Location country, Location division, Location city) where T : class, IAddressable { logger.Info("Adding an additional address to the [{0}] entity with id [{1}].", typeof(T).Name, additionalAddress.GetAddressableEntityId()); addressValidator.ValidateCreate(ToEcaAddressValidationEntity(address: additionalAddress, country: country, division: division, city: city)); var address = additionalAddress.AddAddress(entity); Context.Addresses.Add(address); Context.Locations.Add(address.Location); additionalAddress.Create.SetHistory(address); additionalAddress.Create.SetHistory(address.Location); if (additionalAddress.IsPrimary) { SetAllAddressesNotPrimary(existingAddresses); } return(address); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="additionalAddress"></param> /// <returns></returns> public Task <Address> CreateAsync <T>(AdditionalAddress <T> additionalAddress) where T : class, IAddressable { Contract.Requires(additionalAddress != null, "The additional address must not be null."); Contract.Ensures(Contract.Result <Task <Address> >() != null, "The address returned must not be null."); return(Task.FromResult <Address>(null)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="additionalAddress"></param> /// <returns></returns> public Address Create <T>(AdditionalAddress <T> additionalAddress) where T : class, IAddressable { Contract.Requires(additionalAddress != null, "The additional address must not be null."); Contract.Ensures(Contract.Result <Address>() != null, "The address returned must not be null."); return(null); }