Ejemplo n.º 1
0
        /// <summary>
        /// Sets primary address to last created address.
        /// </summary>
        public virtual void SetPrimaryAddress()
        {
            var masterEntityId     = AddressEntity.GetTypedColumnValue <Guid>(AddressReferenceColumnName);
            var nextPrimaryAddress = new EntitySchemaQuery(UserConnection.EntitySchemaManager, AddressEntityName);

            nextPrimaryAddress.Filters.Add(nextPrimaryAddress.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                                         MasterEntityName, masterEntityId));
            var createdOnColumn = nextPrimaryAddress.AddColumn("CreatedOn");

            nextPrimaryAddress.AddAllSchemaColumns();
            createdOnColumn.OrderByDesc();
            var options = new EntitySchemaQueryOptions {
                PageableDirection       = PageableSelectDirection.First,
                PageableRowCount        = 1,
                PageableConditionValues = new Dictionary <string, object>()
            };
            var collection     = nextPrimaryAddress.GetEntityCollection(UserConnection, options);
            var primaryAddress = collection.Count > 0 ? collection.First() : null;

            if (primaryAddress != null)
            {
                primaryAddress.SetColumnValue("Primary", true);
                primaryAddress.Save();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns master entity.
        /// </summary>
        /// <returns>Master <see cref="Entity"/>.</returns>
        protected virtual Entity GetMasterEntity()
        {
            var masterEntityId = AddressEntity.GetTypedColumnValue <Guid>(AddressReferenceColumnName);

            return(EntitySynchronizationProvider.FindEntity(MasterEntityName, new Dictionary <string, object> {
                { "Id", masterEntityId }
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns address count.
        /// </summary>
        /// <returns>Primary count.</returns>
        public virtual int GetAddressesCount()
        {
            var    masterEntityId     = AddressEntity.GetTypedColumnValue <Guid>(AddressReferenceColumnName);
            Select primaryCountSelect = new Select(UserConnection)
                                        .Column(Func.Count("Id"))
                                        .From(AddressEntityName)
                                        .Where(AddressReferenceColumnName).IsEqual(Column.Parameter(masterEntityId)) as Select;

            return(primaryCountSelect.ExecuteScalar <int>());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Resets rpimary column value.
        /// </summary>
        public virtual void ResetPrimaryColumn()
        {
            var masterEntityId     = AddressEntity.GetTypedColumnValue <Guid>(AddressReferenceColumnName);
            var resetPrimaryColumn = new Update(UserConnection, AddressEntityName)
                                     .Set("Primary", Column.Parameter(false))
                                     .Where(AddressReferenceColumnName).IsEqual(Column.Parameter(masterEntityId))
                                     .And("Id").IsNotEqual(Column.Parameter(AddressEntity.PrimaryColumnValue)) as Update;

            resetPrimaryColumn.Execute();
        }