private IList <Site> GetSitesByPerson(Person person, bool isAdmin, bool isManager)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                IList <Site>       runningList = new List <Site>();
                var                ppDS        = new PersonSiteDataStore(transaction);
                IList <PersonSite> pps         = ppDS.FindSitesByPerson(person.Id, false);
                foreach (PersonSite ppt in pps)
                {
                    if (isAdmin)
                    {
                        if (!ppt.IsAdministrator)
                        {
                            continue;
                        }
                    }
                    if (isManager)
                    {
                        if (!ppt.IsManager)
                        {
                            continue;
                        }
                    }

                    IEnumerable <Site> q = from x in runningList where x.Id.Equals(ppt.Site.Id) select x;
                    if (q.Count() == 0)
                    {
                        runningList.Add(ppt.Site);
                    }
                }
                return(runningList);
            }
        }
        public override void UpdatePersonSite(string personId, bool?isAdministrator, bool?isManager)
        {
            if (isAdministrator == null && isManager == null)
            {
                throw new ArgumentNullException("isAdministrator", "Both isAdministrator and isManager cannot be null");
            }

            using (var transaction = new TransactionScope(_configuration))
            {
                var ds = new PersonSiteDataStore(transaction);
                IList <PersonSite> prs = ds.FindSitesByPerson(personId, false);

                foreach (PersonSite pr in prs)
                {
                    // A value of null for isAdministrator and isManager is equivalent to false.
                    if (!isAdministrator.HasValue)
                    {
                        // Only modify the manager values
                        pr.IsManager = (bool)isManager;

                        if (!pr.IsAdministrator && !pr.IsManager)
                        {
                            ds.Delete(pr.Id);
                        }
                        else
                        {
                            ds.Update(pr);
                        }
                    }
                    else if (!isManager.HasValue)
                    {
                        // Only modify the manager values
                        pr.IsAdministrator = (bool)isAdministrator;

                        if (!pr.IsAdministrator && !pr.IsManager)
                        {
                            ds.Delete(pr.Id);
                        }
                        else
                        {
                            ds.Update(pr);
                        }
                    }
                }
                transaction.Commit();
            }
        }
        public override bool IsPersonInPersonSite(string personId)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var ds = new PersonSiteDataStore(transaction);
                IList <PersonSite> peoples = ds.FindSitesByPerson(personId, false);

                if (peoples.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
 public override Site GetDefaultSiteByPerson(Person person)
 {
     using (TransactionScope transaction = new TransactionScope(_configuration))
     {
         PersonSiteDataStore ppDS        = new PersonSiteDataStore(transaction);
         IList <PersonSite>  pps         = ppDS.FindSitesByPerson(person.Id, true);
         PersonSite          defaultSite = pps.FirstOrDefault(x => x.IsDefault);
         if (defaultSite != null)
         {
             return(defaultSite.Site);
         }
         else
         {
             return(null);
         }
     }
 }
        public override bool IsPersonInPersonSite(Person person, Site site)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var ds = new PersonSiteDataStore(transaction);
                IList <PersonSite> peoples = ds.FindSitesByPerson(person.Id, false);

                IEnumerable <PersonSite> q = from x in peoples where x.Site.Id.Equals(site.Id) select x;

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