Exemplo n.º 1
0
        public ActionResult CreateParentFromToddler(CreateParentViewModel cpvm)
        {
            Person parent = new Person();

            parent.Id        = Guid.NewGuid();
            parent.FirstName = cpvm.FirstName;
            parent.LastName  = cpvm.LastName;
            parent.Gender    = cpvm.Gender;
            db.People.Add(parent);


            Toddler toddler = GetToddler(cpvm.SubjectId);

            if (toddler == null)
            {
                db.SaveChanges();
                return(RedirectToAction("PersonIndex"));
            }


            ContactAssociation ca = NewContactAssociation(toddler.Id, parent.Id, Association.Parent);

            db.ContactAssociations.Add(ca);
            db.SaveChanges();
            return(RedirectToAction("ToddlerDetails", new { id = toddler.Id }));
        }
Exemplo n.º 2
0
        private ContactAssociation NewContactAssociation(Guid subject, Guid create, Association a)
        {
            ContactAssociation ca = new ContactAssociation()
            {
                Contact1Id = subject, Contact2Id = create, Association = a
            };

            return(ca);
        }
Exemplo n.º 3
0
        private ContactAssociation FindContactAssociation(Guid subject, Guid delete)
        {
            ContactAssociation foundca = db.ContactAssociations
                                         .Where(ca => (ca.Contact1Id == subject && ca.Contact2Id == delete) || (ca.Contact2Id == subject && ca.Contact1Id == delete))
                                         .FirstOrDefault();

            if (foundca == null)
            {
                return(null);
            }
            return(foundca);
        }
Exemplo n.º 4
0
        public ActionResult DeleteFromAssociation(Guid subject, Guid delete)
        {
            ContactAssociation thisAssociation = FindContactAssociation(subject, delete);

            if (thisAssociation != null)
            {
                db.ContactAssociations.Remove(thisAssociation);
                db.SaveChanges();
            }
            if (GetToddler(subject) == null)
            {
                return(RedirectToAction("PersonDetails", new { id = subject }));
            }

            return(RedirectToAction("ToddlerDetails", new { id = subject }));
        }
Exemplo n.º 5
0
        public ActionResult AddAssociation(Guid subject, Guid add)
        {
            Boolean            siblings = true;
            Toddler            toddler  = GetToddler(subject);
            Toddler            sibling  = GetToddler(add);
            Person             parent;
            ContactAssociation ca = new ContactAssociation();

            if (toddler == null)
            {
                siblings       = false;
                parent         = GetPerson(subject);
                ca.Contact1Id  = sibling.Id;
                ca.Contact2Id  = parent.Id;
                ca.Association = Association.Parent;
                db.ContactAssociations.Add(ca);
                db.SaveChanges();
                return(RedirectToAction("PersonDetails", new { id = subject }));
            }
            if (sibling == null)
            {
                siblings       = false;
                parent         = GetPerson(add);
                ca.Contact1Id  = toddler.Id;
                ca.Contact2Id  = parent.Id;
                ca.Association = Association.Parent;
                db.ContactAssociations.Add(ca);
                db.SaveChanges();
                return(RedirectToAction("ToddlerDetails", new { id = subject }));
            }
            if (siblings)
            {
                ca.Contact1Id  = toddler.Id;
                ca.Contact2Id  = sibling.Id;
                ca.Association = Association.Sibling;
                db.ContactAssociations.Add(ca);
                db.SaveChanges();
                return(RedirectToAction("ToddlerDetails", new { id = subject }));
            }
            return(RedirectToAction("Index"));
        }
 private static IEnumerable<IContactAssociation> GetOrganizations(Contact contact)
 {
     if (!string.IsNullOrWhiteSpace(contact.Headline))
     {
         var idx = contact.Headline.IndexOf(" at ", StringComparison.Ordinal);
         if (idx > 1)
         {
             var role = contact.Headline.Substring(0, idx);
             var org = contact.Headline.Substring(idx + 4);
             var ass = new ContactAssociation(role, org);
             return new[] { ass };
         }
     }
     return Enumerable.Empty<IContactAssociation>();
 }