private void setImageLink(FamilyMemberViewModel familyMember)
 {
     if (_photoRepository.ImageExists(familyMember.PersonId))
         familyMember.ImageLink = string.Format("/Images/GetImage?personId={0}&imageSize={1}", familyMember.PersonId,
             ImageSize.Small);
     else if (familyMember.FacebookId != string.Empty)
         familyMember.ImageLink = string.Format("https://graph.facebook.com/{0}/picture", familyMember.FacebookId);
     else
         familyMember.ImageLink = string.Empty;
 }
Example #2
0
        private static void UpdateOtherRelationships(FamilyMemberViewModel familyMember, PersonViewModel person, oikonomosEntities context)
        {
            try
            {
                Relationships relationship = (Relationships)Enum.Parse(typeof(Relationships), familyMember.Relationship);
                Relationships oppositeRelationship = Relationships.Unknown;
                Person familyMemberToUpdate = (from p in context.People.Include("PersonRelationships")
                                         where p.PersonId == familyMember.PersonId
                                         select p).FirstOrDefault();

                bool isMale = (from pr in context.PersonRelationships
                               where pr.PersonRelatedToId == person.PersonId
                                    && (pr.RelationshipId == (int)Relationships.Husband ||
                                        pr.RelationshipId == (int)Relationships.Brother ||
                                        pr.RelationshipId == (int)Relationships.Father ||
                                        pr.RelationshipId == (int)Relationships.Grandfather ||
                                        pr.RelationshipId == (int)Relationships.Grandson ||
                                        pr.RelationshipId == (int)Relationships.Son)
                                    select pr).Count()>0;

                bool isFemale = (from pr in context.PersonRelationships
                                 where pr.PersonRelatedToId == person.PersonId
                                    && (pr.RelationshipId == (int)Relationships.Wife ||
                                        pr.RelationshipId == (int)Relationships.Sister ||
                                        pr.RelationshipId == (int)Relationships.Mother ||
                                        pr.RelationshipId == (int)Relationships.Grandmother ||
                                        pr.RelationshipId == (int)Relationships.Granddaughter ||
                                        pr.RelationshipId == (int)Relationships.Daughter)
                                    select pr).Count()>0;

                switch (relationship)
                {
                    case Relationships.Husband:
                        {
                            oppositeRelationship = Relationships.Wife;
                            break;
                        }
                    case Relationships.Wife:
                        {
                            oppositeRelationship = Relationships.Husband;
                            break;
                        }
                    case Relationships.Son:
                    case Relationships.Daughter:
                        {
                            if(isMale)
                            {
                            oppositeRelationship = Relationships.Father;
                            }

                            if(isFemale)
                            {
                                oppositeRelationship = Relationships.Mother;
                            }
                            break;
                        }
                    case Relationships.Brother:
                    case Relationships.Sister:
                        {
                            if(isMale)
                            {
                            oppositeRelationship = Relationships.Brother;
                            }

                            if(isFemale)
                            {
                                oppositeRelationship = Relationships.Sister;
                            }
                            break;
                        }
                    case Relationships.Father:
                    case Relationships.Mother:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Son;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Daughter;
                            }
                            break;
                        }
                    case Relationships.Grandfather:
                    case Relationships.Grandmother:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Grandson;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Granddaughter;
                            }
                            break;
                        }
                    case Relationships.Grandson:
                    case Relationships.Granddaughter:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Grandfather;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Grandmother;
                            }
                            break;
                        }
                }

                if (oppositeRelationship != Relationships.Unknown)
                {
                    AddPersonRelationship(familyMember.PersonId, person.PersonId, (int)oppositeRelationship, familyMemberToUpdate, context);

                    var personToUpdate = FetchPerson(person.PersonId, context, null);

                    //What about the rest of the family
                    if (relationship == Relationships.Husband || relationship == Relationships.Wife)
                    {
                        var spouseRelationships = (from pr in context.PersonRelationships
                                                    where pr.PersonId == familyMember.PersonId
                                                    && (pr.RelationshipId == (int)Relationships.Son ||
                                                        pr.RelationshipId == (int)Relationships.Daughter ||
                                                        pr.RelationshipId == (int)Relationships.Grandson ||
                                                        pr.RelationshipId == (int)Relationships.Granddaughter)
                                                    select pr);

                        foreach (PersonRelationship pr in spouseRelationships)
                        {
                            if (person.PersonId != pr.PersonRelatedToId)
                            {
                                AddPersonRelationship(person.PersonId, pr.PersonRelatedToId, pr.RelationshipId, personToUpdate, context);
                            }
                        }

                    }

                    if (relationship == Relationships.Brother || relationship == Relationships.Sister)
                    {
                        //He has a brother - does the brother have a father, grandfather, mother etc
                        var siblingRelationships = (from pr in context.PersonRelationships
                                                    where pr.PersonId == familyMember.PersonId
                                                    && (pr.RelationshipId == (int)Relationships.Father ||
                                                        pr.RelationshipId == (int)Relationships.Mother ||
                                                        pr.RelationshipId == (int)Relationships.Grandfather ||
                                                        pr.RelationshipId == (int)Relationships.Grandmother ||
                                                        pr.RelationshipId == (int)Relationships.Sister ||
                                                        pr.RelationshipId == (int)Relationships.Brother)
                                                    select pr);

                        foreach (PersonRelationship pr in siblingRelationships)
                        {
                            if (person.PersonId != pr.PersonRelatedToId)
                            {
                                AddPersonRelationship(personToUpdate.PersonId, pr.PersonRelatedToId, pr.RelationshipId, personToUpdate, context);
                            }
                        }

                    }

                    //if (relationship == Relationships.Father || relationship == Relationships.Mother)
                    //{
                    //    //He has a brother - does the brother have a father, grandfather, mother etc
                    //    var siblingRelationships = (from pr in context.PersonRelationships
                    //                                where pr.PersonId == familyMember.PersonId
                    //                                && (pr.RelationshipId == (int)Relationships.Father ||
                    //                                    pr.RelationshipId == (int)Relationships.Mother ||
                    //                                    pr.RelationshipId == (int)Relationships.Grandfather ||
                    //                                    pr.RelationshipId == (int)Relationships.Grandmother ||
                    //                                    pr.RelationshipId == (int)Relationships.Sister ||
                    //                                    pr.RelationshipId == (int)Relationships.Brother)
                    //                                select pr);

                    //    foreach (PersonRelationship pr in siblingRelationships)
                    //    {
                    //        AddPersonRelationship(personToUpdate.PersonId, pr.PersonRelatedToId, pr.RelationshipId, personToUpdate, context);
                    //    }

                    //}
                }

            }
            catch { }
        }
        private void UpdateOtherRelationships(FamilyMemberViewModel familyMember, PersonViewModel person)
        {
            try
            {
                var relationship = (Relationships)Enum.Parse(typeof(Relationships), familyMember.Relationship);
                var oppositeRelationship = Relationships.Unknown;
                var familyMemberToUpdate = (from p in Context.People.Include("PersonRelationships")
                                               where p.PersonId == familyMember.PersonId
                                               select p).FirstOrDefault();

                var isMale = (from pr in Context.PersonRelationships
                               where pr.PersonRelatedToId == person.PersonId
                                     && (pr.RelationshipId == (int)Relationships.Husband ||
                                         pr.RelationshipId == (int)Relationships.Brother ||
                                         pr.RelationshipId == (int)Relationships.Father ||
                                         pr.RelationshipId == (int)Relationships.Grandfather ||
                                         pr.RelationshipId == (int)Relationships.Grandson ||
                                         pr.RelationshipId == (int)Relationships.Son)
                               select pr).Any();

                var isFemale = (from pr in Context.PersonRelationships
                                 where pr.PersonRelatedToId == person.PersonId
                                       && (pr.RelationshipId == (int)Relationships.Wife ||
                                           pr.RelationshipId == (int)Relationships.Sister ||
                                           pr.RelationshipId == (int)Relationships.Mother ||
                                           pr.RelationshipId == (int)Relationships.Grandmother ||
                                           pr.RelationshipId == (int)Relationships.Granddaughter ||
                                           pr.RelationshipId == (int)Relationships.Daughter)
                                 select pr).Any();

                switch (relationship)
                {
                    case Relationships.Husband:
                        {
                            oppositeRelationship = Relationships.Wife;
                            break;
                        }
                    case Relationships.Wife:
                        {
                            oppositeRelationship = Relationships.Husband;
                            break;
                        }
                    case Relationships.Son:
                    case Relationships.Daughter:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Father;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Mother;
                            }
                            break;
                        }
                    case Relationships.Brother:
                    case Relationships.Sister:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Brother;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Sister;
                            }
                            break;
                        }
                    case Relationships.Father:
                    case Relationships.Mother:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Son;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Daughter;
                            }
                            break;
                        }
                    case Relationships.Grandfather:
                    case Relationships.Grandmother:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Grandson;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Granddaughter;
                            }
                            break;
                        }
                    case Relationships.Grandson:
                    case Relationships.Granddaughter:
                        {
                            if (isMale)
                            {
                                oppositeRelationship = Relationships.Grandfather;
                            }

                            if (isFemale)
                            {
                                oppositeRelationship = Relationships.Grandmother;
                            }
                            break;
                        }
                }

                if (oppositeRelationship == Relationships.Unknown) return;
                AddPersonRelationship(familyMember.PersonId, person.PersonId, (int)oppositeRelationship, familyMemberToUpdate);

                var personToUpdate = _personRepository.FetchPerson(person.PersonId, null);

                //What about the rest of the family
                if (relationship == Relationships.Husband || relationship == Relationships.Wife)
                {
                    var spouseRelationships = (from pr in Context.PersonRelationships
                                               where pr.PersonId == familyMember.PersonId
                                                     && (pr.RelationshipId == (int)Relationships.Son ||
                                                         pr.RelationshipId == (int)Relationships.Daughter ||
                                                         pr.RelationshipId == (int)Relationships.Grandson ||
                                                         pr.RelationshipId == (int)Relationships.Granddaughter)
                                               select pr);

                    foreach (var pr in spouseRelationships.Where(pr => person.PersonId != pr.PersonRelatedToId))
                    {
                        AddPersonRelationship(person.PersonId, pr.PersonRelatedToId, pr.RelationshipId, personToUpdate);
                    }
                }

                if (relationship != Relationships.Brother && relationship != Relationships.Sister) return;
                //He has a brother - does the brother have a father, grandfather, mother etc
                var siblingRelationships = (from pr in Context.PersonRelationships
                                            where pr.PersonId == familyMember.PersonId
                                                  && (pr.RelationshipId == (int)Relationships.Father ||
                                                      pr.RelationshipId == (int)Relationships.Mother ||
                                                      pr.RelationshipId == (int)Relationships.Grandfather ||
                                                      pr.RelationshipId == (int)Relationships.Grandmother ||
                                                      pr.RelationshipId == (int)Relationships.Sister ||
                                                      pr.RelationshipId == (int)Relationships.Brother)
                                            select pr);

                foreach (var pr in siblingRelationships.Where(pr => person.PersonId != pr.PersonRelatedToId))
                {
                    AddPersonRelationship(personToUpdate.PersonId, pr.PersonRelatedToId, pr.RelationshipId, personToUpdate);
                }
            }
            catch { }
        }