Пример #1
0
        /// <summary>
        /// Gets an instance of a property matching the specified id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public XSubmittal PropertyValueSubmittal_Get(Guid id)
        {
            XSubmittal submittal = this._dal.Get(id);

            XPropertyDomain pLayer = new XPropertyDomain();

            foreach (XValue pv in submittal.PropertyValues)
            {
                pv.Property = pLayer.DisplayValue(pv.PropertyId);
            }

            return(submittal);
        }
Пример #2
0
        private bool Approve(XSubmittal submittal, Guid userId)
        {
            //Helpers.Log("PropertyValueSubmittalLayer", "PropertyValueSubmittal_Approve()");

            if (submittal != null)
            {
                foreach (XValue pv in submittal.PropertyValues)
                {
                    pv.Approved   = DateTime.Now;
                    pv.ApprovedBy = userId;
                    pv.IsDirty    = true;
                }

                submittal.Approved   = DateTime.Now;
                submittal.ApprovedBy = userId;
                submittal.IsDirty    = true;

                //List<SynchTrigger> triggers = this.CreateSynchTriggers(submittal);

                this.Save(submittal, false, userId);
                //new SynchTriggerDal().Save(triggers);

                List <Guid> propIds = new List <Guid>();
                foreach (XValue pv in submittal.PropertyValues)
                {
                    if (!propIds.Contains(pv.PropertyId))
                    {
                        propIds.Add(pv.PropertyId);
                    }
                }

                IDictionary <Guid, IXProperty> properties = new XPropertyDomain().GetObjectDictionary(propIds);

                foreach (XValue pv in submittal.PropertyValues)
                {
                    IXProperty prop = properties[pv.PropertyId];

                    if (prop != null)
                    {
                        XObjectRelation relation = null;

                        if ((prop.DataType == EDataType.Relation_ParentChild) || (prop.DataType == EDataType.Relation_ChildParent))
                        {
                            #region Relations

                            // need to create a relation for this item
                            relation = new XObjectRelation();

                            if (prop.DataType == EDataType.Relation_ParentChild)
                            {
                                relation.FromAssetId = pv.AssetId;
                                relation.ToAssetId   = new Guid(pv.Value);
                            }
                            else
                            {
                                relation.FromAssetId = new Guid(pv.Value);
                                relation.ToAssetId   = pv.AssetId;
                            }

                            relation.AssetRelationType = EObjectRelationType.ParentChild;

                            #endregion
                        }
                        else if (prop.DataType == EDataType.Dependency)
                        {
                            #region Dependency
                            relation                   = new XObjectRelation();
                            relation.FromAssetId       = pv.AssetId;
                            relation.ToAssetId         = new Guid(pv.Value);
                            relation.AssetRelationType = EObjectRelationType.Dependency;
                            #endregion
                        }
                        else if ((prop.DataType == EDataType.User) && (prop.RoleId.HasValue))
                        {
                            // TODO: Complete implementation of the dynamic role-based security

                            if (!string.IsNullOrEmpty(pv.Value))
                            {
                                Guid memberId;

                                if (Guid.TryParse(pv.Value, out memberId))
                                {
                                    XRoleDomain roleLayer = new XRoleDomain();
                                    if (!roleLayer.ContainsUser(prop.RoleId.Value, memberId))
                                    {
                                        //roleLayer.AddMemberToRole(memberId, prop.RoleId.Value, Constants.MemberIds.Admin);
                                    }
                                }
                            }

                            // determine if someone else is already in this value
                            // if they are, we need to determine whether or not they are in this role for another asset
                            // if not, remove the role association
                            // if they are, do nothing
                            // determine whether or not the newly-supplied user is in this role
                            // if not, add them to the role
                            // if they are, do nothing
                        }

                        if (prop.IsSystem && (prop.SystemType == ESystemType.AssetName))
                        {
                            bool renamed = new XObjectDomain <XObject>().Rename(pv.AssetId, pv.Value);
                        }

                        if (relation != null)
                        {
                            #region more relation stuff

                            relation.Created    = DateTime.Now;
                            relation.CreatedBy  = submittal.CreatedBy;
                            relation.Approved   = relation.Created;
                            relation.ApprovedBy = submittal.CreatedBy;

                            XObjectRelationDomain relationDal = new XObjectRelationDomain();

                            // a child can only have one parent
                            // delete any previous relations
                            if (prop.DataType == EDataType.Relation_ChildParent)
                            {
                                relationDal.RemoveExistingParentRelations(relation.FromAssetId, relation.AssetRelationType.GetHashCode());
                            }

                            if (!relationDal.AssetAssetRelationExists(relation.FromAssetId, relation.ToAssetId, relation.AssetRelationType.GetHashCode()))
                            {
                                relationDal.Save(relation);
                            }

                            // TODO: Need more logic in here.  Other cases
                            // What if relation is removed?

                            #endregion
                        }
                    }
                }

                return(new XObjectDomain().MarkAsUpdated(submittal.AssetId, submittal.CreatedBy));
            }

            return(false);
        }