Exemplo n.º 1
0
        public static Data.Comment SaveComment(IDBSession dbs, Data.Comment comment)
        {
            using (NHibernate.ITransaction transaction = dbs.Session.BeginTransaction())
            {
                DB.Comment dbComment = null;
                if (comment.ID != Guid.Empty)
                {
                    dbComment = dbs.Session.Get <DB.Comment>(comment.ID);
                }
                if (dbComment == null)
                {
                    dbComment         = new DB.Comment(comment);
                    dbComment.Created = DateTime.UtcNow;
                }
                else
                {
                    dbComment.Author  = comment.Author;
                    dbComment.Content = comment.Content;
                }


                DB.Message dbMessage = dbs.Session.QueryOver <DB.Message>().Fetch(x => x.Comments).Eager.Where(x => x.ID == comment.MessageID).SingleOrDefault <DB.Message>();
                if (dbMessage != null)
                {
                    dbMessage.Comments.Add(dbComment);
                    dbs.Session.SaveOrUpdate(dbMessage);
                    transaction.Commit();
                    comment = dbComment.ToData(false);
                }
                else
                {
                    dbs.Session.SaveOrUpdate(dbComment);
                    transaction.Commit();
                    comment = dbComment.ToData(false);
                }
            }
            return(comment);
        }
Exemplo n.º 2
0
 public static Data.Comment LoadComment(IDBSession dbs, Guid id)
 {
     DB.Comment   dbComment = dbs.Session.Get <DB.Comment>(id);
     Data.Comment comment   = dbComment?.ToData(false);
     return(comment);
 }