예제 #1
0
        private static int GetOrCreateDiscussionId(
            ISession session,
            int accountid,
            Type type,
            int objectid,
            ManagedSecurityContext sec)
        {
            Discussion d = Find(session, accountid, type, objectid, sec);

            if (d != null)
            {
                return(d.Id);
            }

            ManagedDiscussionMapEntry mapentry = ManagedDiscussionMap.Find(type);

            TransitDiscussion td = new TransitDiscussion();

            td.AccountId    = accountid;
            td.Name         = mapentry.Name;
            td.Personal     = true;
            td.Description  = string.Empty;
            td.Created      = td.Modified = DateTime.UtcNow;
            td.ObjectId     = objectid;
            td.DataObjectId = ManagedDataObject.Find(session, type);

            // creating a discussion that belongs to a different user (commenting on someone's items)
            ManagedDiscussion      m_d   = new ManagedDiscussion(session);
            ManagedSecurityContext o_sec = new ManagedSecurityContext(session, accountid);

            return(m_d.CreateOrUpdate(td, o_sec));
        }
예제 #2
0
        public override Discussion GetInstance(ISession session, ManagedSecurityContext sec)
        {
            Discussion instance = base.GetInstance(session, sec);

            if (Id == 0)
            {
                instance.Account  = GetOwner(session, AccountId, sec);
                instance.Personal = this.Personal;
                instance.ObjectId = this.ObjectId;
                if (this.ObjectId != 0)
                {
                    if (this.DataObjectId != 0)
                    {
                        instance.DataObject = session.Load <DataObject>(this.DataObjectId);
                    }
                    else if (!string.IsNullOrEmpty(this.ParentObjectType))
                    {
                        instance.DataObject = ManagedDataObject.FindObject(session, this.ParentObjectType);
                    }
                }
            }

            instance.Name            = this.Name;
            instance.Description     = this.Description;
            instance.DefaultView     = this.DefaultView;
            instance.DefaultViewRows = this.DefaultViewRows;
            return(instance);
        }
예제 #3
0
        public static Discussion Find(
            ISession session,
            int accountid,
            Type type,
            int objectid,
            ManagedSecurityContext sec)
        {
            DataObject dataobject = ManagedDataObject.FindObject(session, type);

            Discussion instance = (Discussion)
                                  session.CreateCriteria(typeof(Discussion))
                                  .Add(Expression.Eq("DataObject.Id", dataobject.Id))
                                  .Add(Expression.Eq("Account.Id", accountid))
                                  .Add(Expression.Eq("ObjectId", objectid))
                                  .Add(Expression.Eq("Personal", true))
                                  .SetMaxResults(1)
                                  .UniqueResult();

            if (instance == null)
            {
                return(null);
            }

            ManagedDiscussion m_instance = new ManagedDiscussion(session, instance);

            m_instance.GetACL().Check(sec, DataOperation.Retreive);
            return(instance);
        }
예제 #4
0
 public static IList <MadLibInstance> GetMadLibs(ISession session, string table, int id)
 {
     return(session.CreateCriteria(typeof(MadLibInstance))
            .Add(Expression.Eq("DataObject.Id", ManagedDataObject.Find(session, table)))
            .Add(Expression.Eq("ObjectId", id))
            .List <MadLibInstance>());
 }
예제 #5
0
 public static IList <Feature> GetFeatures(ISession session, string table, int id)
 {
     return(session.CreateCriteria(typeof(Feature))
            .Add(Expression.Eq("DataObject.Id", ManagedDataObject.Find(session, table)))
            .Add(Expression.Eq("DataRowId", id))
            .List <Feature>());
 }
예제 #6
0
        public override MadLibInstance GetInstance(ISession session, ManagedSecurityContext sec)
        {
            MadLibInstance instance = base.GetInstance(session, sec);

            if (Id == 0)
            {
                instance.MadLib = session.Load <MadLib>(this.MadLibId);
            }
            instance.Text       = this.Text;
            instance.ObjectId   = this.ObjectId;
            instance.DataObject = ManagedDataObject.FindObject(session, this.ObjectName);
            instance.AccountId  = this.AccountId;
            return(instance);
        }
예제 #7
0
        public static int GetDiscussionPostCount(ISession session, int accountid, Type type, int objectid)
        {
            DataObject dataobject = ManagedDataObject.FindObject(session, type);

            Discussion existingtagdiscussion = (Discussion)session.CreateCriteria(typeof(Discussion))
                                               .Add(Expression.Eq("DataObject.Id", dataobject.Id))
                                               .Add(Expression.Eq("Account.Id", accountid))
                                               .Add(Expression.Eq("ObjectId", (objectid == 0) ? null : (object)objectid))
                                               .Add(Expression.Eq("Personal", true))
                                               .UniqueResult();

            if (existingtagdiscussion == null)
            {
                return(0);
            }

            return(GetDiscussionPostCount(session, existingtagdiscussion.Id));
        }
예제 #8
0
        public static bool FindAndDelete(
            ISession session,
            Type type,
            int objectid,
            ManagedSecurityContext sec)
        {
            DataObject         dataobject  = ManagedDataObject.FindObject(session, type);
            IList <Discussion> discussions = session.CreateCriteria(typeof(Discussion))
                                             .Add(Expression.Eq("DataObject.Id", dataobject.Id))
                                             .Add(Expression.Eq("ObjectId", objectid))
                                             .Add(Expression.Eq("Personal", true))
                                             .List <Discussion>();

            foreach (Discussion discussion in discussions)
            {
                ManagedDiscussion m_instance = new ManagedDiscussion(session, discussion);
                m_instance.Delete(sec);
            }

            return(discussions.Count > 0);
        }
예제 #9
0
 public static int Delete(ISession session, string table, int id)
 {
     return(session.Delete(string.Format("from Feature f where f.DataObject.Id = {0} AND f.DataRowId = {1}",
                                         ManagedDataObject.Find(session, table), id)));
 }
예제 #10
0
 public static int GetLatestFeatureId(ISession session, string objectname, int rowid)
 {
     return(GetLatestFeatureId(session, ManagedDataObject.Find(session, objectname), rowid));
 }