Esempio n. 1
0
        /// <summary>
        /// Gets an enumeration list from the underlying data model.
        /// </summary>
        /// <param name="modelProperty">Enumeration list's data model property name</param>
        /// <returns></returns>
        protected List <Enumeration> GetEnumerationList(string modelProperty)
        {
            List <Enumeration> returnList = new List <Enumeration>();

            if (DynamicObjectHelpers.HasProperty(this.CurrentObject, modelProperty))
            {
                var     objectData = (IDictionary <string, object>) this.CurrentObject;
                dynamic objectList = objectData[modelProperty];

                foreach (dynamic obj in objectList)
                {
                    if (obj.Id == null)
                    {
                        continue;
                    }

                    returnList.Add(new Enumeration(obj.Id, obj.Name, obj.Name, true, false));
                }

                return(returnList);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a primitive value by property name.
        /// </summary>
        /// <typeparam name="T">Primitive type</typeparam>
        /// <param name="modelProperty">Primitive's data model property name</param>
        /// <returns></returns>
        protected T GetPrimitiveValue <T>(string modelProperty)
        {
            if (DynamicObjectHelpers.HasProperty(this.CurrentObject, modelProperty))
            {
                return(DynamicObjectHelpers.GetProperty <T>(this.CurrentObject, modelProperty));
            }

            return(default(T));
        }
Esempio n. 3
0
        /// <summary>
        /// Sets an enumeration in the underlying data model.
        /// </summary>
        /// <param name="modelProperty">Enumeration's data model property name</param>
        /// <param name="value">New enumeration value</param>
        /// <param name="objectProperty">Derived object's property name, if it is different than the data model property name. Note that this will automatically be set to the caller's member name.</param>
        protected void SetEnumeration(string modelProperty, Enumeration value, [CallerMemberName] string objectProperty = null)
        {
            if (this.ReadOnly)
            {
                throw new CiresonReadOnlyException("Cannot set enumeration; this object is read-only.");
            }

            var objectData = (IDictionary <string, object>) this.CurrentObject;

            // Add a new Expando if the model property doesn't exist
            if (!DynamicObjectHelpers.HasProperty(this.CurrentObject, modelProperty))
            {
                objectData.Add(modelProperty, new ExpandoObject());
            }

            dynamic rawEnum = objectData[modelProperty];

            if (value == null)
            {
                rawEnum.Id   = null;
                rawEnum.Name = string.Empty;
            }
            else if (value.Id == Guid.Empty)
            {
                rawEnum.Id   = null;
                rawEnum.Name = string.Empty;
            }
            else
            {
                rawEnum.Id   = value.Id;
                rawEnum.Name = value.Name;
            }

            this.CurrentObject = (ExpandoObject)objectData;
            this.IsDirty       = true;

            if (String.IsNullOrEmpty(objectProperty))
            {
                NotifyPropertyChanged(modelProperty);
            }
            else
            {
                NotifyPropertyChanged(objectProperty);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a related object based on a relationship.
        /// </summary>
        /// <typeparam name="T">Type of the related object</typeparam>
        /// <param name="modelProperty">Relationship's data model property name</param>
        /// <returns></returns>
        protected T GetRelatedObject <T>(string modelProperty) where T : TypeProjection
        {
            if (DynamicObjectHelpers.HasProperty(this.CurrentObject, modelProperty))
            {
                var objectData = (IDictionary <string, object>) this.CurrentObject;

                BindingFlags flags   = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
                CultureInfo  culture = null;
                T            relObj  = (T)Activator.CreateInstance(typeof(T), flags, null, null, culture);

                relObj.CurrentObject = (ExpandoObject)objectData[modelProperty];
                relObj.ReadOnly      = true;

                return(relObj);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets an enumeration from the underlying data model.
        /// </summary>
        /// <param name="modelProperty">Enumeration's data model property name</param>
        /// <returns></returns>
        protected Enumeration GetEnumeration(string modelProperty)
        {
            if (DynamicObjectHelpers.HasProperty(this.CurrentObject, modelProperty))
            {
                var     objectData = (IDictionary <string, object>) this.CurrentObject;
                dynamic rawEnum    = objectData[modelProperty];

                if (rawEnum.Id == null)
                {
                    return(null);
                }

                return(new Enumeration(rawEnum.Id, rawEnum.Name, rawEnum.Name, true, false));
            }
            else
            {
                return(null);
            }
        }