public void UpdateRelationMapping([FromUri] int contextId, [FromUri] int parentId, [FromUri] string propertyAlias, [FromUri] string relationTypeAlias, [FromUri] bool relationsOnly, [FromBody] dynamic data)
        {
            IRelationType relationType = ApplicationContext.Services.RelationService.GetRelationTypeByAlias(relationTypeAlias);

            if (relationType != null)
            {
                // WARNING: Duplicate code
                // get all relations of this type
                IEnumerable <IRelation> relations = ApplicationContext.Services.RelationService.GetAllRelationsByRelationType(relationType.Id);

                // construct object used to identify a relation (this is serialized into the relation comment field)
                RelationMappingComment relationMappingComment = new RelationMappingComment(contextId, propertyAlias);

                if (relationType.IsBidirectional && relationsOnly)
                {
                    relations = relations.Where(x => x.ChildId == contextId || x.ParentId == contextId);
                    relations = relations.Where(x => new RelationMappingComment(x.Comment).DataTypeDefinitionId == relationMappingComment.DataTypeDefinitionId);
                }
                else
                {
                    relations = relations.Where(x => x.ChildId == contextId);
                    relations = relations.Where(x => new RelationMappingComment(x.Comment).PropertyTypeId == relationMappingComment.PropertyTypeId);

                    if (relationMappingComment.IsInArchetype())
                    {
                        relations = relations.Where(x => new RelationMappingComment(x.Comment).MatchesArchetypeProperty(relationMappingComment.PropertyAlias));
                    }
                }

                // clear any existing relations
                foreach (IRelation relation in relations)
                {
                    ApplicationContext.Services.RelationService.Delete(relation);
                }

                // create new relations
                LegacyRelationType legacyRelationType = new LegacyRelationType(relationType.Id);

                // ensure context type is valid
                if (uQuery.GetUmbracoObjectType(contextId) == legacyRelationType.GetChildUmbracoObjectType())
                {
                    foreach (int pickedId in ((JArray)data).Select(x => x.Value <int>()))
                    {
                        // ensure picked type is valid
                        if (uQuery.GetUmbracoObjectType(pickedId) == legacyRelationType.GetParentUmbracoObjectType())
                        {
                            LegacyRelation.MakeNew(pickedId, contextId, legacyRelationType, relationMappingComment.GetComment());
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void syncCapacity()
        {
            int max      = this.Capacity;
            int signedUp = this.SignedUp;
            int waiting  = this.OnWaitingList;

            //2 scenarios, either the room is now smaller or bigger
            if (max >= signedUp)
            {
                Log.Add(LogTypes.Debug, _content.Id, "bigger cap");

                //get people on the waitinglist and promote them to coming to event
                int          diff   = max - signedUp;
                RelationType coming = RelationType.GetByAlias("event");
                foreach (Relation r in Relations.EventRelation.GetPeopleWaiting(_content.Id, diff))
                {
                    Log.Add(LogTypes.Debug, _content.Id, "R:" + r.Id.ToString());
                    r.RelType = coming;
                    r.Save();
                }
            }
            else
            {
                Log.Add(LogTypes.Debug, _content.Id, "smaller cap");

                //get people on the signedup list and put the people who signed up last on the waiting list.
                //remember to preserve the original sign-up date
                int          diff        = signedUp - max;
                RelationType waitinglist = RelationType.GetByAlias("waitinglist");
                foreach (Relation r in Relations.EventRelation.GetPeopleSignedUpLast(_content.Id, diff))
                {
                    Log.Add(LogTypes.Debug, _content.Id, "R:" + r.Id.ToString());
                    r.RelType = waitinglist;
                    r.Save();
                }
            }
        }
 /// <summary>
 /// check that alias hasn't been changed to clash with another (except itself)
 /// </summary>
 /// <param name="source">the aliasCustomValidator control</param>
 /// <param name="args">to set validation respose</param>
 protected void AliasCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
 {
     args.IsValid = (RelationType.GetByAlias(this.aliasTextBox.Text.Trim()) == null) ||
                    (this.aliasTextBox.Text.Trim() == this._relationType.Alias);
 }
Beispiel #4
0
        public void UpdateRelationMapping([FromUri] int contextId, [FromUri] string propertyAlias, [FromUri] string relationTypeAlias, [FromUri] bool relationsOnly, [FromBody] dynamic data)
        {
            IRelationType relationType = ApplicationContext.Services.RelationService.GetRelationTypeByAlias(relationTypeAlias);

            if (relationType != null)
            {
                // WARNING: Duplicate code
                // get all relations of this type
                IEnumerable<IRelation> relations = ApplicationContext.Services.RelationService.GetAllRelationsByRelationType(relationType.Id);

                // construct object used to identify a relation (this is serialized into the relation comment field)
                RelationMappingComment relationMappingComment = new RelationMappingComment(contextId, propertyAlias);

                if (relationType.IsBidirectional && relationsOnly)
                {
                    relations = relations.Where(x => x.ChildId == contextId || x.ParentId == contextId);
                    relations = relations.Where(x => new RelationMappingComment(x.Comment).DataTypeDefinitionId == relationMappingComment.DataTypeDefinitionId);
                }
                else
                {
                    relations = relations.Where(x => x.ChildId == contextId);
                    relations = relations.Where(x => new RelationMappingComment(x.Comment).PropertyTypeId == relationMappingComment.PropertyTypeId);
                }

                // clear any existing relations
                foreach (IRelation relation in relations)
                {
                    ApplicationContext.Services.RelationService.Delete(relation);
                }

                // create new relations
                LegacyRelationType legacyRelationType = new LegacyRelationType(relationType.Id);

                // ensure context type is valid
                if (uQuery.GetUmbracoObjectType(contextId) == legacyRelationType.GetChildUmbracoObjectType())
                {
                    foreach (int pickedId in ((JArray)data).Select(x => x.Value<int>()))
                    {
                        // ensure picked type is valid
                        if (uQuery.GetUmbracoObjectType(pickedId) == legacyRelationType.GetParentUmbracoObjectType())
                        {
                            LegacyRelation.MakeNew(pickedId, contextId, legacyRelationType, relationMappingComment.GetComment());
                        }
                    }
                }
            }
        }