/*
         * protected override void Initialize()
         * {
         *  base.Initialize();
         * }
         *
         * protected override void OnUndoCommandExecuted()
         * {
         *  base.OnUndoCommandExecuted();
         *
         *  //this.Layout();
         * }
         *
         * protected override void OnRedoCommandExecuted()
         * {
         *  base.OnRedoCommandExecuted();
         *
         *  //this.Layout();
         * }
         *
         * private void Layout()
         * {
         *  if (this.Store.InUndoRedoOrRollback)
         *  {
         *      return;
         *  }
         *
         *  // disable undo manager
         *  this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
         *
         *  // create transation to apply layout information
         *  using (Transaction t = this.Store.TransactionManager.BeginTransaction("Layout"))
         *  {
         *      // layout diagram
         *      DiagramLayouter.Layout(this.Diagram);
         *
         *      t.Commit();
         *  }
         *
         *  // enable undo manager
         *  this.Store.UndoManager.UndoState = UndoState.Enabled;
         * }
         *
         * public override void OnChildShapeElementAdded(Microsoft.VisualStudio.Modeling.ElementAddedEventArgs args)
         * {
         *  base.OnChildShapeElementAdded(args);
         *
         *  this.Layout();
         * }
         *
         * public override void OnChildShapeElementRemoved(ElementDeletedEventArgs args)
         * {
         *  base.OnChildShapeElementRemoved(args);
         *
         *  this.Layout();
         * }
         *
         * public override void OnLinkShapeElementAdded(ElementAddedEventArgs args)
         * {
         *  base.OnLinkShapeElementAdded(args);
         *
         *  this.Layout();
         * }
         *
         * public override void OnLinkShapeElementRemoved(ElementDeletedEventArgs args)
         * {
         *  base.OnLinkShapeElementRemoved(args);
         *
         *  this.Layout();
         * }
         *
         */

        protected override bool CanCreateRelationshipShapeMarriedToShape(PDE.ToolFramework.Modeling.Visualization.ViewModel.DiagramSurface.ViewModelRelationshipCreationInfo info)
        {
            FamilyTreePerson source = info.Source.Element as global::Tum.FamilyTreeDSL.FamilyTreePerson;
            FamilyTreePerson target = info.Target.Element as global::Tum.FamilyTreeDSL.FamilyTreePerson;

            if (source == null || target == null)
            {
                return(false);
            }

            if (source.Husband != null || source.Wife != null)
            {
                return(false);
            }

            if (target.Husband != null || target.Wife != null)
            {
                return(false);
            }

            if (source == target)
            {
                return(false);
            }

            return(base.CanCreateRelationshipShapeMarriedToShape(info));
        }
        private bool HasChild(FamilyTreePerson parent, FamilyTreePerson child)
        {
            if (parent.Children.Contains(child))
            {
                return(true);
            }

            foreach (FamilyTreePerson c in parent.Children)
            {
                if (HasChild(c, child))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public async Task <FamilyTree> CreateFamilyTreeAsync(FamilyTree treeToCreate)
        {
            if (!(Enum.IsDefined(typeof(FamilyTreeTypesEnum), treeToCreate.Type)))
            {
                throw new InvalidObjectException("Invalid type of FamilyTree", nameof(Entity.FamilyTree), 0);
            }

            if (!(ExistsInDb <User>(treeToCreate.UserId)))
            {
                throw new ObjectNotFoundException(nameof(Entity.User), treeToCreate.UserId);
            }


            var result = await Create(treeToCreate);

            var familytreePersonservice = ResolveService <IFamilyTreePersonService>();

            FamilyTreePerson reference = new FamilyTreePerson {
                FamilyTree = null, FamilyTreeId = result.Id, Person = null, PersonId = result.StartPersonId
            };
            await familytreePersonservice.PutPersonToFamilyTreeAsync(reference);

            return(result);
        }
Пример #4
0
        public async Task <IEnumerable <FamilyTreePerson> > GetFamilyTree()
        {
            var peopleDb = await _personRepository.FindAllPeople();

            var familyTreePeople = new List <FamilyTreePerson>();

            foreach (var personDb in peopleDb)
            {
                var familyTreePerson = new FamilyTreePerson
                {
                    Id        = personDb.Key,
                    Title     = personDb.Value.PreferredName,
                    Spouses   = new List <int>(),
                    Parents   = new List <int>(),
                    BirthDate = personDb.Value.BirthRangeStart
                };

                familyTreePerson.Description = FindDates(personDb.Value);

                if (personDb.Value.Gender == Gender.Female)
                {
                    familyTreePerson.ItemTitleColor = "#FDD7E4";
                    familyTreePerson.Image          = "/img/Female.png";
                }

                if (personDb.Value.Gender == Gender.Male)
                {
                    familyTreePerson.Image = "/img/Male.png";
                }


                if (!string.IsNullOrWhiteSpace(personDb.Value?.Portrait))
                {
                    familyTreePerson.Image = $"familytree/thumbnail/{personDb.Value.Portrait}";
                }

                var spouses = personDb.Value.Relationships.Where(r =>
                                                                 r.Relationship == Relationship.Husband || r.Relationship == Relationship.Wife ||
                                                                 r.Relationship == Relationship.Spouse).ToList();

                foreach (var spouse in spouses)
                {
                    familyTreePerson.Spouses.Add(spouse.PersonId);
                }

                var parents = personDb.Value.Relationships.Where(r =>
                                                                 r.Relationship == Relationship.Father || r.Relationship == Relationship.Mother ||
                                                                 r.Relationship == Relationship.Parent).ToList();

                foreach (var parent in parents)
                {
                    familyTreePerson.Parents.Add(parent.PersonId);
                }

                familyTreePeople.Add(familyTreePerson);
            }

            foreach (var person in familyTreePeople)
            {
                if (person.Parents.Any())
                {
                    var siblings = familyTreePeople.FindAll(p => p.Parents.Contains(person.Parents.First()))
                                   .OrderBy(p => p.BirthDate);

                    short position   = 0;
                    int   relativeId = 0;
                    foreach (var sibling in siblings)
                    {
                        if (position == 0)
                        {
                            relativeId = sibling.Id;
                        }
                        else
                        {
                            sibling.RelativeItem  = relativeId;
                            sibling.PlacementType = AdviserPlacementType.Right;
                            sibling.Position      = position;
                        }

                        position++;
                    }
                }
            }
            return(familyTreePeople);
        }
        private bool HasChild(FamilyTreePerson parent, FamilyTreePerson child)
        {
            if (parent.Children.Contains(child))
                return true;

            foreach (FamilyTreePerson c in parent.Children)
                if (HasChild(c, child))
                    return true;

            return false;
        }