/// <summary> /// 创建一个主题 /// </summary> /// <param name="entity"></param> /// <returns></returns> public void CreateThread(NewThreadModel model) { //创建主题仓储 //IForumThreadRepository forumThreadRep = FBS.Factory.Factory<IForumThreadRepository>.GetConcrete(); //IAccountRepository accountRep = FBS.Factory.Factory<IAccountRepository>.GetConcrete(); //IForumsRepository forumsRep = FBS.Factory.Factory<IForumsRepository>.GetConcrete(); IRepository <ForumThread> threadRep = Factory.Factory <IRepository <ForumThread> > .GetConcrete <ForumThread>(); IRepository <ThreadRootMessage> msgRep = Factory.Factory <IRepository <ThreadRootMessage> > .GetConcrete <ThreadRootMessage>(); //Account creater = null; ForumThread topic = null; ThreadRootMessage rootMsg = null; //帖子内容对象 MessageVO messageVO = new MessageVO(); messageVO.Body = model.Body; messageVO.Subject = model.Title; try { //creater = accountRep.GetByKey(model.AccountID); rootMsg = new ThreadRootMessage(messageVO, model.AccountID, model.ForumID); topic = new ForumThread(rootMsg, model.ForumID); //topic.RootMessage = rootMsg; threadRep.Add(topic); msgRep.Add(rootMsg); threadRep.PersistAll(); msgRep.PersistAll(); //forumThreadRep.Add(topic); //forumThreadRep.PersistAll(); } catch { throw new AddForumThreadException("添加主题至仓储时异常"); } }
/// <summary> /// 从数据库构造根帖 /// </summary> /// <param name="reader">数据读取器</param> /// <returns>根帖</returns> internal ThreadRootMessage BuildRootMessage(IDataReader reader) { //新实例 //ThreadRootMessage rootmsg = ThreadRootMessage.CreateFromPersist( // new Guid(reader["MessageID"].ToString()), // Convert.ToDateTime(reader["CreationDate"]), // Convert.ToDateTime(reader["ModifiedDate"]), // new Guid(reader["AccountID"].ToString()), // new Guid(reader["ForumID"].ToString()), // new MessageVO() // { // Body = Utils.Utils.HtmlDecode(reader["Body"].ToString()), // Subject = reader["Subject"].ToString(), // RewardPoints = Convert.ToInt32(reader["RewardPoints"]) // }); ThreadRootMessage rootmsg = ThreadRootMessage.CreateFromReader(reader); return(rootmsg); }
/// <summary> /// 对主题进行回复 /// </summary> /// <param name="forumThread">主题实体</param> /// <param name="forumMessageReply">回复消息实体</param> public void ReplyThread(ReplyThreadModel model) { //IForumThreadRepository forumThreadRep = FBS.Factory.Factory<IForumThreadRepository>.GetConcrete(); //IAccountRepository accountRep = FBS.Factory.Factory<IAccountRepository>.GetConcrete(); //IForumsRepository forumsRep = FBS.Factory.Factory<IForumsRepository>.GetConcrete(); //IForumMessageRepository msgRep = FBS.Factory.Factory<IForumMessageRepository>.GetConcrete(); IRepository <ForumMessage> msgRep = Factory.Factory <IRepository <ForumMessage> > .GetConcrete <ForumMessage>(); IForumThreadRepository threadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IRepository <Forum> forumRep = Factory.Factory <IRepository <Forum> > .GetConcrete <Forum>(); IRepository <ForumThread> threadWriteRep = Factory.Factory <IRepository <ForumThread> > .GetConcrete <ForumThread>(); ForumMessageReply reply = null; ThreadRootMessage rootmsg = null; Forum forum = null; ForumThread thread = null; MessageVO mVO = new MessageVO(); mVO.Body = model.Body; try { thread = threadRep.GetByKey(model.ThreadID); rootmsg = thread.RootMessage; forum = forumRep.GetByKey(model.ForumID); //主题回复数增加 thread.AddMessageCount(); //forum = forumsRep.GetByKey(rootmsg.Forum); //poster = accountRep.GetByKey(model.AccountID); //回复 reply = new ForumMessageReply(mVO, model.AccountID, model.ForumID, rootmsg.Id, thread.Id); //加入板块的最后发表并对板块回复计数 forum.AddNewMessage(reply); //更新帖子 thread.ModifiedDate = reply.CreationDate; //thread.CreationDate = reply.CreationDate; //给主题增加回复 msgRep.Add(reply); msgRep.PersistAll(); threadWriteRep.Update(thread); threadWriteRep.PersistAll(); forumRep.Update(forum); forumRep.PersistAll(); //forumThreadRep.Update(thread); //forumThreadRep.PersistAll(); } catch (Exception error) { throw new ReplyForumThreadException("回复失败,原因为:", error); } }