Beispiel #1
0
        public bool CanWrite(int user_id)
        {
            if (mInstance.Account.Id == user_id)
            {
                return(true);
            }

            ManagedPlace m_place = new ManagedPlace(Session, mInstance.Place);

            if (m_place.CanWrite(user_id))
            {
                return(true);
            }

            return(false);
        }
        public override ACL GetACL(Type type)
        {
            ACL acl = new ManagedPlace(Session, mInstance.Place).GetACL(type);

            return(acl);
        }
Beispiel #3
0
        public void Merge(ManagedSecurityContext sec, int id)
        {
            if (id == mInstance.Id)
            {
                throw new Exception("Cannot merge a place into itself.");
            }

            ManagedPlace p = new ManagedPlace(Session, id);

            #region Merge AccountEvents

            foreach (AccountEvent inst in p.Instance.AccountEvents)
            {
                inst.Place = mInstance;
                Session.Save(inst);
            }

            #endregion

            #region Merge AccountGroupPlace

            foreach (AccountGroupPlace inst in p.Instance.AccountGroupPlaces)
            {
                if (!HasAccountGroup(inst.AccountGroup.Id))
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge AccountPlaceFavorite

            foreach (AccountPlaceFavorite inst in p.Instance.AccountPlaceFavorites)
            {
                bool found = false;
                foreach (AccountPlaceFavorite curr in inst.Account.AccountPlaceFavorites)
                {
                    if (curr.Place.Id == mInstance.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge AccountPlaceRequests

            foreach (AccountPlaceRequest inst in p.Instance.AccountPlaceRequests)
            {
                bool found = false;
                foreach (AccountPlaceRequest curr in inst.Account.AccountPlaceRequests)
                {
                    if (curr.Place.Id == mInstance.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge AccountPlaces

            foreach (AccountPlace inst in p.Instance.AccountPlaces)
            {
                bool found = false;
                foreach (AccountPlace curr in inst.Account.AccountPlaces)
                {
                    if (curr.Place.Id == mInstance.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge PlaceAttribute

            foreach (PlaceAttribute inst in p.Instance.PlaceAttributes)
            {
                if (!HasPlaceAttribute(inst.Attribute.Id))
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge PlaceNames

            // merge place names
            foreach (PlaceName inst in p.Instance.PlaceNames)
            {
                if (!HasPlaceName(inst.Name))
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge PlacePictures

            foreach (PlacePicture inst in p.Instance.PlacePictures)
            {
                inst.Place = mInstance;
                Session.Save(inst);
            }

            #endregion

            #region Merge PlacePropertyValues

            foreach (PlacePropertyValue inst in p.Instance.PlacePropertyValues)
            {
                if (!HasPlacePropertyValue(inst.PlaceProperty.Id))
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge PlaceQueueItems

            foreach (PlaceQueueItem inst in p.Instance.PlaceQueueItems)
            {
                bool found = false;
                foreach (PlaceQueue queue in inst.PlaceQueue.Account.PlaceQueues)
                {
                    foreach (PlaceQueueItem curr in queue.PlaceQueueItems)
                    {
                        if (curr.Place.Id == mInstance.Id)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }

                if (!found)
                {
                    inst.Place = mInstance;
                    Session.Save(inst);
                }
            }

            #endregion

            #region Merge Discussion

            // TODO: move into ManagedDiscussion

            Discussion d_keep   = ManagedDiscussion.Find(Session, mInstance.Account.Id, typeof(Place), mInstance.Id, sec);
            Discussion d_delete = ManagedDiscussion.Find(Session, p.Instance.Account.Id, typeof(Place), p.Instance.Id, sec);

            if (d_keep == null && d_delete != null)
            {
                d_delete.ObjectId = mInstance.Id;
                Session.Save(d_delete);
            }
            else if (d_delete != null)
            {
                foreach (DiscussionThread t in d_delete.DiscussionThreads)
                {
                    t.Discussion = d_keep;
                    if (t.Modified > d_keep.Modified)
                    {
                        d_keep.Modified = t.Modified;
                        Session.Save(d_keep);
                    }
                    Session.Save(t);
                }
            }

            #endregion

            #region Merge MadLibs

            IList <MadLibInstance> madlibs = ManagedMadLibInstance.GetMadLibs(Session, "Place", p.Id);
            foreach (MadLibInstance madlib in madlibs)
            {
                madlib.ObjectId = mInstance.Id;
                Session.Save(madlib);
            }

            #endregion

            #region Merge Features

            IList <Feature> features = ManagedFeature.GetFeatures(Session, "Place", p.Id);
            foreach (Feature feature in features)
            {
                feature.DataRowId = mInstance.Id;
                Session.Save(feature);
            }

            #endregion

            Session.Delete(p.Instance);
        }