public IList <PersonRelationship> GetPersonRelationships(Person p)
        {
            PersonRelationship     rel = null;
            PersonRelationshipType t   = null;

            var subquery = QueryOver.Of <PersonResponsibility>()
                           .Where(x => x.Person != p)
                           .And(x => !x.Archive)
                           .Select(x => x.Person);

            return(Session.QueryOver <PersonRelationship>(() => rel)
                   .JoinAlias(() => rel.PersonRelationshipType, () => t, JoinType.InnerJoin)
                   .Where(() => !rel.Archive)
                   .And(Restrictions.Disjunction()
                        .Add(() => rel.SubjectPerson == p)
                        .Add(() => rel.ObjectPerson == p)
                        )
                   .AndRestrictionOn(() => t.Code).IsIn(new string[]
            {
                PersonRelationshipType.CODE_ACTED_TOGETHER_WITH,
                PersonRelationshipType.CODE_BELONGED_TO_THE_SAME_GROUP_AS,
                PersonRelationshipType.CODE_FOUGHT_IN_THE_SAME_GROUP_AS,
                PersonRelationshipType.CODE_FOUGHT_WITH,
                PersonRelationshipType.CODE_IS_A_SUBORDINATE_OF,
                PersonRelationshipType.CODE_IS_A_SUPERIOR_TO,
                PersonRelationshipType.CODE_IS_THE_BODYGUARD_OF,
                PersonRelationshipType.CODE_IS_THE_DEPUTY_OF,
                PersonRelationshipType.CODE_PROVIDED_WEAPONS_AND_AMMUNITION_TO
            })
                   .And(Restrictions.Disjunction()
                        .Add(Subqueries.WhereProperty(() => rel.SubjectPerson).In(subquery))
                        .Add(Subqueries.WhereProperty(() => rel.ObjectPerson).In(subquery))
                        )
                   .List());
        }
        public ActionResult Edit(int id)
        {
            PersonRelationshipType type = this.personTasks.GetPersonRelationshipType(id);

            if (type != null)
            {
                return(View(new PersonRelationshipTypeViewModel(type)));
            }
            return(new HttpNotFoundResult());
        }
Esempio n. 3
0
 public bool DeletePersonRelationshipType(PersonRelationshipType type)
 {
     if (type != null)
     {
         if (!type.PersonRelationships.Any())
         {
             this.personRelationshipTypeRepo.Delete(type);
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
 public PersonRelationshipTypeViewModel(PersonRelationshipType t)
 {
     if (t != null)
     {
         this.Id = t.Id;
         this.PersonRelationshipTypeName = t.PersonRelationshipTypeName;
         this.IsCommutative    = t.IsCommutative;
         this.Archive          = t.Archive;
         this.Notes            = t.Notes;
         this.NumRelationships = t.PersonRelationships.Count;
     }
 }
 public ActionResult Create(PersonRelationshipTypeViewModel vm)
 {
     if (ModelState.IsValid)
     {
         PersonRelationshipType type = new PersonRelationshipType();
         type.PersonRelationshipTypeName = vm.PersonRelationshipTypeName;
         type.IsCommutative = vm.IsCommutative;
         type.Archive       = vm.Archive;
         type.Notes         = vm.Notes;
         type.Code          = vm.PersonRelationshipTypeName.ToUpper().Replace(' ', '_');
         type = this.personTasks.SavePersonRelationshipType(type);
         return(RedirectToAction("Details", new { id = type.Id }));
     }
     return(Create());
 }
Esempio n. 6
0
        public JsonNetResult Name(int id)
        {
            PersonRelationshipType type = this.personTasks.GetPersonRelationshipType(id);

            if (type != null)
            {
                return(JsonNet(new
                {
                    Id = id,
                    Name = type.PersonRelationshipTypeName
                }));
            }
            else
            {
                return(JsonNet(string.Empty));
            }
        }
        public ActionResult Delete(int id)
        {
            PersonRelationshipType type = this.personTasks.GetPersonRelationshipType(id);

            if (type != null)
            {
                if (this.personTasks.DeletePersonRelationshipType(type))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Details", new { id = id }));
                }
            }
            return(new HttpNotFoundResult());
        }
        public ActionResult Edit(PersonRelationshipTypeViewModel vm)
        {
            PersonRelationshipType         type  = this.personTasks.GetPersonRelationshipType(vm.Id);
            IList <PersonRelationshipType> types = this.personTasks.GetPersonRelationshipTypesByName(vm.PersonRelationshipTypeName);

            if (type != null && types != null && types.Any() && types.Where(x => x.Id != type.Id).Any())
            {
                ModelState.AddModelError("PersonRelationshipTypeName", "Relationship type already exists.");
            }
            if (ModelState.IsValid)
            {
                type.PersonRelationshipTypeName = vm.PersonRelationshipTypeName;
                type.IsCommutative = vm.IsCommutative;
                type.Archive       = vm.Archive;
                type.Notes         = vm.Notes;
                type = this.personTasks.SavePersonRelationshipType(type);
                return(RedirectToAction("Details", new { id = vm.Id }));
            }
            return(Edit(vm.Id));
        }
Esempio n. 9
0
 public PersonRelationshipType SavePersonRelationshipType(PersonRelationshipType type)
 {
     return(this.personRelationshipTypeRepo.SaveOrUpdate(type));
 }