public override bool IsUserInPersonType(string userName, string personTypeId)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var pptDS = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> peoples = pptDS.FindPersonByPersonType(personTypeId);

                // Find the person who corresponds to username.
                var  uDS  = new UserDataStore(transaction);
                User user = uDS.FindByName(_applicationName, userName);

                // If there is no matching person, then do not continue.
                if (user.Person == null)
                {
                    throw new PersonNotFoundException(user.Name);
                }

                IEnumerable <PersonPersonType> q = from x in peoples where x.Person.Id.Equals(user.Person.Id) select x;

                if (q.Count() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public override bool IsPersonInPersonTypeAdmin(Person person)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var        ds = new PersonTypeDataStore(transaction);
                PersonType adminPersonType = ds.FindByName(BusiBlocksConstants.AdministratorsGroup);

                if (adminPersonType == null)
                {
                    return(false);
                }

                var pds = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> personTypes = pds.FindByPersonAndPersonType(person.Id, adminPersonType.Id);

                if (personTypes.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public override IList <PersonType> GetPersonTypesByUser(string userName)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                // Find all the Persons who match the MembershipUser id of 'username'.
                var  userDS = new UserDataStore(transaction);
                User user   = userDS.FindByName(_applicationName, userName);

                // If there is no matching person, then do not continue.
                if (user.Person == null)
                {
                    throw new PersonNotFoundException(user.Name);
                }

                // Then, find all the PersonTypes via PersonPersonType that match the personIds.
                IList <PersonType> runningList = new List <PersonType>();
                var ppDS = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> pps = ppDS.FindPersonTypesByPerson(user.Person.Id);
                foreach (PersonPersonType ppt in pps)
                {
                    IEnumerable <PersonType> q = from x in runningList where x.Id.Equals(ppt.PersonType.Id) select x;
                    if (q.Count() == 0)
                    {
                        runningList.Add(ppt.PersonType);
                    }
                }
                return(runningList);
            }
        }
        public override IList <Person> GetAllPersonsByPersonType(PersonType personType)
        {
            IList <Person> personList = new List <Person>();

            using (var transaction = new TransactionScope(_configuration))
            {
                // Find all the persons in the person person type table.
                var ds = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> personPersonTypes = ds.FindPersonByPersonType(personType.Id);
                personList = personPersonTypes.Select(x => x.Person).ToList <Person>();
            }
            return(personList);
        }
        private IList <string> GetAdminIds()
        {
            // First get all the system admin ids.
            using (var transaction = new TransactionScope(_configuration))
            {
                var        ds2 = new PersonTypeDataStore(transaction);
                PersonType sysAdminPersonType = ds2.FindByName(BusiBlocksConstants.AdministratorsGroup);

                var ds1 = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> sysAdmins   = ds1.FindPersonByPersonType(sysAdminPersonType.Id);
                IList <string>           sysAdminIds = sysAdmins.Select(x => x.Person.Id).ToList <string>();
                return(sysAdminIds);
            }
        }
 public override void CreatePersonPersonType(string personId, string personTypeId)
 {
     // Create a new record in the PersonPersonType table.
     using (var transaction = new TransactionScope(_configuration))
     {
         var pptDS = new PersonPersonTypeDataStore(transaction);
         var ppt   = new PersonPersonType();
         var pDS   = new PersonDataStore(transaction);
         ppt.Person = pDS.FindByKey(personId);
         var ptDS = new PersonTypeDataStore(transaction);
         ppt.PersonType = ptDS.FindByKey(personTypeId);
         pptDS.Insert(ppt);
         transaction.Commit();
     }
 }
        public override void DeletePersonFromPersonType(string personId, string personTypeId)
        {
            // Delete a record in the PersonPersonType table.
            using (var transaction = new TransactionScope(_configuration))
            {
                var pptDS = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> ppts = pptDS.FindByPersonAndPersonType(personId, personTypeId);

                foreach (PersonPersonType item in ppts)
                {
                    item.Deleted = true;
                    pptDS.Update(item);
                }

                transaction.Commit();
            }
        }
        public override bool IsPersonInPersonType(string personId)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var pptDS = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> peoples = pptDS.FindPersonTypesByPerson(personId);

                if (peoples.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
 public override IList <PersonType> GetPersonTypesByPerson(Person person)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         IList <PersonType> runningList = new List <PersonType>();
         var ppDS = new PersonPersonTypeDataStore(transaction);
         IList <PersonPersonType> pps = ppDS.FindPersonTypesByPerson(person.Id);
         foreach (PersonPersonType ppt in pps)
         {
             IEnumerable <PersonType> q = from x in runningList where x.Id.Equals(ppt.PersonType.Id) select x;
             if (q.Count() == 0)
             {
                 runningList.Add(ppt.PersonType);
             }
         }
         return(runningList);
     }
 }
        public override bool IsPersonInPersonType(Person person, PersonType personType)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var pptDS = new PersonPersonTypeDataStore(transaction);
                IList <PersonPersonType> peoples = pptDS.FindPersonByPersonType(personType.Id);

                IEnumerable <PersonPersonType> q = from x in peoples where x.Person.Id.Equals(person.Id) select x;

                if (q.Count() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }