public string UpdateRelationshipState(string passportNumber1, string passportNumber2, string updatedState, string mode)
        {
            try
            {
                string message = "relationship updated successfully";
                try
                {
                    //ищем отношение в БД
                    var result = from r in Relationships.GetContent()
                                 from p1 in Persones.GetContent()
                                 from p2 in Persones.GetContent()
                                 where ((p1.PassportNumber == passportNumber1) &&
                                        (p2.PassportNumber == passportNumber2) &&
                                        (((r.FirstPersonID == p2.PersonID) && (r.SecondPersonID == p1.PersonID)) ||
                                        ((r.FirstPersonID == p1.PersonID) && (r.SecondPersonID == p2.PersonID))))
                                 select new { r, p1, p2.PersonID };
                    //если нашли - обновляем
                    if (result.Count() != 0)
                    {
                        var r = result.First();
                        int relativeID = r.PersonID;
                        if (r.r.SecondPersonID == r.p1.PersonID)
                        {
                            r.r.State = updatedState;
                        }
                        else
                        {
                            //если необходимо - инвертируем
                            #region Relationship logic
                            string state = "";
                            if ((updatedState == "son") || (updatedState == "daughter"))
                            {
                                if (r.p1.Sex == "male") { state = "father"; } else { state = "mother"; }
                            }
                            else if ((updatedState == "mother") || (updatedState == "father"))
                            {
                                if (r.p1.Sex == "male") { state = "son"; } else { state = "daughter"; }
                            }
                            else if ((updatedState == "sister") || (updatedState == "brother"))
                            {
                                if (r.p1.Sex == "male") { state = "brother"; } else { state = "sister"; }
                            }
                            else if ((updatedState == "wife") || (updatedState == "husband"))
                            {
                                if (r.p1.Sex == "male") { state = "husband"; } else { state = "wife"; }
                            }
                            else if ((updatedState == "grandson") || (updatedState == "granddaughter"))
                            {
                                if (r.p1.Sex == "male") { state = "grandfather"; } else { state = "grandmother"; }
                            }
                            else if ((updatedState == "grandfather") || (updatedState == "grandmother"))
                            {
                                if (r.p1.Sex == "male") { state = "grandson"; } else { state = "granddaughter"; }
                            }
                            else if ((updatedState == "aunt") || (updatedState == "uncle"))
                            {
                                if (r.p1.Sex == "male") { state = "nephew"; } else { state = "niece"; }
                            }
                            else if ((updatedState == "nephew") || (updatedState == "niece"))
                            {
                                if (r.p1.Sex == "male") { state = "uncle"; } else { state = "aunt"; }
                            }
                            #endregion
                            r.r.State = state;
                        }
                        if (mode == "auto")
                        {
                            //получаем список родственников персоны с pasportNumber1 - отправившей запрос персоны
                            ToDispose = false;
                            List<Relative> relatives = GetRelativesList(passportNumber1, null);
                            ToDispose = true;
                            if (relatives.Count != 0)
                            {
                                Relationship relationship;
                                foreach (var rel in relatives)
                                {
                                    relationship = null;
                                    string newState = "";
                                    int count;
                                    if (relativeID != rel.Person.PersonID)
                                    {
                                        //определям существует ли уже отношение между отредактированным родственником
                                        //и другим родственником из списка 
                                        var resultRS = from rs in Relationships.GetContent()
                                                       where (((rs.FirstPersonID == relativeID) && (rs.SecondPersonID == rel.Person.PersonID)) ||
                                                             ((rs.FirstPersonID == rel.Person.PersonID) && (rs.SecondPersonID == relativeID)))
                                                       select rs;

                                        count = resultRS.Count();

                                        //пытаемся определить новое отношение
                                        switch (updatedState)
                                        {
                                            #region Relationship logic
                                            case ("son"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "brother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "grandson";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "nephew";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                                {
                                                    newState = "son";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("daughter"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "sister";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "granddaughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "niece";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                                {
                                                    newState = "daughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("father"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "grandfather";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if (rel.RelationshipState == "mother")
                                                {
                                                    newState = "husband";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "father";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("mother"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "grandmother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if (rel.RelationshipState == "father")
                                                {
                                                    newState = "wife";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "mother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("sister"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "aunt";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "daughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "sister";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "grandfather") || (rel.RelationshipState == "grandmother"))
                                                {
                                                    newState = "granddaughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "aunt") || (rel.RelationshipState == "uncle"))
                                                {
                                                    newState = "niece";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "niece") || (rel.RelationshipState == "nephew"))
                                                {
                                                    newState = "aunt";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("brother"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "uncle";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "son";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "brother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "grandfather") || (rel.RelationshipState == "grandmother"))
                                                {
                                                    newState = "grandson";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "aunt") || (rel.RelationshipState == "uncle"))
                                                {
                                                    newState = "nephew";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                else if ((rel.RelationshipState == "niece") || (rel.RelationshipState == "nephew"))
                                                {
                                                    newState = "uncle";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("wife"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "mother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("husband"):
                                                if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                                {
                                                    newState = "father";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("aunt"):
                                                if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "aunt";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("uncle"):
                                                if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "uncle";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("grandfather"):
                                                if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "grandfather";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("grandmother"):
                                                if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                                {
                                                    newState = "grandmother";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("granddaughter"):
                                                if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                                {
                                                    newState = "granddaughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("grandson"):
                                                if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                                {
                                                    newState = "grandson";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("nephew"):
                                                if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "grandson";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            case ("niece"):
                                                if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                                {
                                                    newState = "granddaughter";
                                                    relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                                }
                                                break;
                                            #endregion
                                        }

                                        if (relationship != null)
                                        {
                                            if (count == 0)
                                            {
                                                //если определили отношение, которого не существовало - добавляем
                                                Relationships.Insert(relationship);
                                            }
                                            else
                                            {
                                                //если определили отношение, которого уже существовало - заменяем, если необходимо
                                                var RS = resultRS.First();
                                                if (relationship.State != RS.State)
                                                {
                                                    ToDispose = false;
                                                    UpdateRelationshipState(rel.Person.PassportNumber, passportNumber2, relationship.State, "manually");
                                                    ToDispose = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //если не определили новое отношение, но существовало старое - удаляем его
                                            if (count != 0)
                                            {
                                                ToDispose = false;
                                                DeleteRelative(rel.Person.PassportNumber, passportNumber2);
                                                ToDispose = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        Context.SubmitChanges();
                    }
                    else
                    {
                        message = "relationship between " + passportNumber1 + " and " + passportNumber2 + " doesn't exist";
                    }
                }
                catch (Exception e)
                {
                    message = e.Message;
                }
                return message;
            }
            finally
            {
                if (ToDispose) Context.Dispose();
            }
        }
 public string AddRelative(string pasportNumber, Relative relative, string mode)
 {
     try
     {
         string message = "relative added successfully";
         int personID = 0;
         int relativeID = 0;
         Relationship relationship;
         try
         {
             //проверяем есть ли уже родственник в таблице Persones, если нет - добавляем
             var tryRelative = from p in Persones.GetContent() where p.PassportNumber == relative.Person.PassportNumber select p.PersonID;
             if (tryRelative.Count() == 0)
             {
                 if ((relative.Person.DateOfBirth != null) && (relative.Person.DateOfBirth.Value.Year < 1900)) relative.Person.DateOfBirth = null;
                 Persones.Insert(relative.Person);
                 Context.SubmitChanges();
                 relativeID = relative.Person.PersonID;
             }
             else
             {
                 relativeID = tryRelative.First();
             }
             var tryPerson = (from p in Persones.GetContent() where p.PassportNumber == pasportNumber select p).FirstOrDefault();
             if (tryPerson != null) { personID = tryPerson.PersonID; }
             else { return "there's no person in DB with passport number " + pasportNumber; }
             //запрашиваем список родственников персоны
             ToDispose = false;
             List<Relative> relatives = GetRelativesList(pasportNumber, null);
             ToDispose = true;
             //проверяем существует ли уже между персоной и родственником отношение, если нет - создаем
             if (relatives.Where(rel => rel.Person.PersonID == relativeID).Count() == 0)
             {
                 relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = personID, State = relative.RelationshipState };
                 Relationships.Insert(relationship);
             }
             if ((relatives.Count != 0) && (mode == "auto"))
             {
                 foreach (var rel in relatives)
                 {
                     relationship = null;
                     string newState = "";
                     //проверяем есть ли в базе отношение между добавленным родственником и существующим, если нет - 
                     //пытаемся определить тип отношения и добавить
                     var result = from r in Relationships.GetContent()
                                  where (((r.FirstPersonID == relativeID) && (r.SecondPersonID == rel.Person.PersonID)) ||
                                        ((r.FirstPersonID == rel.Person.PersonID) && (r.SecondPersonID == relativeID)))
                                  select r.RelationshipID;
                     if ((result.Count() == 0) && (relativeID != rel.Person.PersonID))
                     {
                         switch (relative.RelationshipState)
                         {
                             //определение типа родственного отношения, читается как:
                             //если новый родственник приходится мне тем-то(case) и у меня есть тот-то(if),
                             //то новый родственник приходится старому тем-то(newState)
                             #region Relationship logic
                             case ("son"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "brother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "grandson";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "nephew";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                 {
                                     newState = "son";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("daughter"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "sister";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "granddaughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "niece";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                 {
                                     newState = "daughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("father"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "grandfather";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if (rel.RelationshipState == "mother")
                                 {
                                     newState = "husband";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "father";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("mother"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "grandmother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if (rel.RelationshipState == "father")
                                 {
                                     newState = "wife";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "mother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("sister"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "aunt";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "daughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "sister";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "grandfather") || (rel.RelationshipState == "grandmother"))
                                 {
                                     newState = "granddaughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "aunt") || (rel.RelationshipState == "uncle"))
                                 {
                                     newState = "niece";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "niece") || (rel.RelationshipState == "nephew"))
                                 {
                                     newState = "aunt";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("brother"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "uncle";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "son";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "brother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "grandfather") || (rel.RelationshipState == "grandmother"))
                                 {
                                     newState = "grandson";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "aunt") || (rel.RelationshipState == "uncle"))
                                 {
                                     newState = "nephew";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 else if ((rel.RelationshipState == "niece") || (rel.RelationshipState == "nephew"))
                                 {
                                     newState = "uncle";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("wife"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "mother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("husband"):
                                 if ((rel.RelationshipState == "son") || (rel.RelationshipState == "daughter"))
                                 {
                                     newState = "father";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("aunt"):
                                 if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "aunt";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("uncle"):
                                 if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "uncle";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("grandfather"):
                                 if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "grandfather";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("grandmother"):
                                 if ((rel.RelationshipState == "sister") || (rel.RelationshipState == "brother"))
                                 {
                                     newState = "grandmother";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("granddaughter"):
                                 if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                 {
                                     newState = "granddaughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("grandson"):
                                 if ((rel.RelationshipState == "wife") || (rel.RelationshipState == "husband"))
                                 {
                                     newState = "grandson";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("nephew"):
                                 if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "grandson";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             case ("niece"):
                                 if ((rel.RelationshipState == "father") || (rel.RelationshipState == "mother"))
                                 {
                                     newState = "granddaughter";
                                     relationship = new Relationship { RelationshipID = 0, FirstPersonID = relativeID, SecondPersonID = rel.Person.PersonID, State = newState };
                                 }
                                 break;
                             #endregion
                         }
                         if (relationship != null) Relationships.Insert(relationship);
                     }
                 }
             }
             Context.SubmitChanges();
         }
         catch (Exception e)
         {
             message = e.Message;
         }
         return message;
     }
     finally
     {
         if (ToDispose) Context.Dispose();
     }
 }