public virtual async Task <object> AddAddress(object entityId, IAddressEntity address)
        {
            if (entityId == null)
            {
                throw new ArgumentNullException(nameof(entityId));
            }

            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var dbmodel = await this.Get(entityId, this.DbSet);

            if (dbmodel == null)
            {
                throw new EntityNotFoundException();
            }

            var dbaddress = await this.AddOrGetAddress(address);

            dbmodel.Addresses.Add(dbaddress);

            return(dbmodel);
        }
 /// <summary>
 /// What types of addresses does this command station support?
 /// </summary>
 public override IEnumerable <AddressType> GetSupportedAddressTypes(IAddressEntity entity)
 {
     if (entity is ILoc)
     {
         yield return(AddressType.Dcc);
     }
 }
Esempio n. 3
0
        public static void MapTo <TLocationReferenceEntity>(this Address address, IAddressEntity <TLocationReferenceEntity> entity)
            where TLocationReferenceEntity : class, ILocationReferenceEntity, new()
        {
            // Need to ensure that objects match what is in the database.

            if (entity.id != Guid.Empty)
            {
                address.Id = entity.id;
            }

            entity.line1 = address.Line1;
            entity.line2 = address.Line2;

            // Try to update in place.

            if (address.Location != null)
            {
                if (entity.LocationReferenceEntity == null)
                {
                    entity.LocationReferenceEntity = address.Location.MapTo <TLocationReferenceEntity>();
                }
                else
                {
                    address.Location.MapTo(entity.LocationReferenceEntity);
                }
            }
        }
Esempio n. 4
0
 public UserAccountEntity(
     IBaseSettings pBaseSettings,
     IUserEntity pUserManager,
     IAddressEntity pAddressManager) : base(pBaseSettings, nameof(User_Account))
 {
     _userManager    = pUserManager;
     _addressManager = pAddressManager;
 }
Esempio n. 5
0
 public static Address Map <TLocationReferenceEntity>(this IAddressEntity <TLocationReferenceEntity> entity, ILocationQuery locationQuery)
     where TLocationReferenceEntity : class, ILocationReferenceEntity
 {
     return(new Address
     {
         Id = entity.id,
         Line1 = entity.line1,
         Line2 = entity.line2,
         Location = entity.LocationReferenceEntity == null ? null : entity.LocationReferenceEntity.Map(locationQuery),
     });
 }
        /// <summary>
        /// What types of addresses does this command station support?
        /// </summary>
        public override IEnumerable <AddressType> GetSupportedAddressTypes(IAddressEntity entity)
        {
            if (entity is ILoc)
            {
                yield return(AddressType.Dcc);

                yield return(AddressType.Motorola);
            }
            else
            {
                yield return(AddressType.LocoNet);
            }
        }
        protected virtual async Task <Address> AddOrGetAddress(IAddressEntity address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var dbaddress = await this.AddOrGet(
                new Address(address),
                this.AddressSet,
                t => (t.AddressString == address.AddressString) &&
                (t.CountryId == address.CountryId) &&
                (t.CityId == address.CityId));

            return(dbaddress);
        }
Esempio n. 8
0
        public Address(IAddressEntity entity)
            : this()
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            this.AddressString  = entity.AddressString;
            this.CountryId      = entity.CountryId;
            this.CityId         = entity.CityId;
            this.CreatedByUser  = entity.CreatedByUser;
            this.ModifiedByUser = entity.ModifiedByUser;
            this.DateCreated    = entity.DateCreated;
            this.DateModified   = entity.DateModified;
        }
Esempio n. 9
0
        /// <summary>
        /// Select the command station used to drive the given entity
        /// </summary>
        /// <returns>The selected command station or null if there is no match</returns>
        internal CommandStationState SelectCommandStation(IAddressEntity entity)
        {
            // Is an address configured?
            var address = entity.Address;

            if (address == null)
            {
                return(null);
            }
            // Lookup a preferred command station
            var network   = address.Network;
            var preferred = GetPreferredCommandStationState(address.Type);

            if (preferred != null)
            {
                if (preferred.Supports(entity, network))
                {
                    return((CommandStationState)preferred);
                }
            }
            // Look for a command station to control me
            var csSelection = CommandStationStates.Where(x => x.Supports(entity, network)).ToList();

            if (csSelection.Count == 0)
            {
                return(null);
            }
            // Look for the best matching command station
            // Select exact match
            var commandStation = csSelection.FirstOrDefault(x => x.SupportsExact(entity, network));

            if (commandStation == null)
            {
                // No exact match
                if (csSelection.Count > 1)
                {
                    // We cannot make a good choice
                    return(null);
                }
                return((CommandStationState)csSelection[0]);
            }
            return((CommandStationState)commandStation);
        }
Esempio n. 10
0
        /// <summary>
        /// Can this command station be used to serve the given network?
        /// </summary>
        /// <param name="entity">The entity being search for.</param>
        /// <param name="network">The network in question</param>
        /// <param name="exactMatch">Set to true when there is an exact match in address type and address space, false otherwise.</param>
        public bool Supports(IAddressEntity entity, Network network, out bool exactMatch)
        {
            exactMatch = false;
            if (!Entity.GetSupportedAddressTypes(entity).Contains(network.Type))
            {
                return(false);
            }
            // There is a match in type, look for an exact match
            var addressSpace = network.AddressSpace;

            if (string.IsNullOrEmpty(addressSpace))
            {
                // No address space specified, so no exact match
                return(true);
            }
            exactMatch = addressSpaces.Any(x => string.Equals(addressSpace, x, StringComparison.OrdinalIgnoreCase));
            if ((addressSpaces.Length > 0) && !exactMatch)
            {
                // We have specific address spaces we support, the network has a different specific
                // address space, so we do not support it
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// What types of addresses does this command station support?
 /// </summary>
 public override IEnumerable <AddressType> GetSupportedAddressTypes(IAddressEntity entity)
 {
     return(GetSupportedAddressTypes());
 }
Esempio n. 12
0
 public override Address Map(IAddressEntity source) => new Address(source.Address1, source.City, new State(source.State), new ZipCode(source.ZipCode), source.Address2);
Esempio n. 13
0
 /// <summary>
 /// What types of addresses does this command station support?
 /// The result may vary depending on the type of the given entity
 /// </summary>
 public abstract IEnumerable <AddressType> GetSupportedAddressTypes(IAddressEntity entity);
Esempio n. 14
0
        /// <summary>
        /// Does the given command station support the given network exact?
        /// </summary>
        public static bool SupportsExact(this ICommandStationState cs, IAddressEntity entity, Network network)
        {
            bool exact;

            return(cs.Supports(entity, network, out exact) && exact);
        }