commentservice.cs
来自「该项目中对 SQLHelper 类进行了简单封装」· CS 代码 · 共 154 行
CS
154 行
/*
* CommentService.cs @Microsoft Visual Studio 2005 <.NET Framework 2.0>
* AfritXia
* 02.09/2007
*
* 评论服务
*
*/
using System;
using System.Collections.Generic;
using NET.AfritXia.MyHome.DBTask.Definition;
using NET.AfritXia.MyHome.Extension.Definition;
using NET.AfritXia.MyHome.Model.Message;
using NET.AfritXia.MyHome.ServiceInterface;
namespace NET.AfritXia.MyHome.InternalService
{
/// <summary>
/// 评论服务实现类
/// </summary>
public class CommentService : ServiceBase, ICommentService
{
#region 类构造器
/// <summary>
/// 类默认构造器
/// </summary>
public CommentService()
{
}
#endregion
#region ICommentService 成员
public void Append(Comment newComment)
{
using (IDBTaskTransaction tranx = MyDBTaskFactory.CreateDBTaskTransaction())
{
// 创建评论数据库任务
ICommentTask task = MyDBTaskFactory.CreateCommentTask();
// 创建评论扩展
ICommentExtension ext = MyExtensionFactory.CreateCommentExtension();
// 登记数据库事务
task.EnlistTransaction(tranx);
ext.EnlistTransactionObject(tranx);
// 设置活动用户名称
ext.Actor = this.Actor;
try
{
// 准备添加评论
ext.OnPreAppend(newComment);
// 添加评论
task.Append(newComment);
// 添加评论完成
ext.OnAppendComplete(newComment);
// 提交事务
tranx.Commit();
}
catch
{
// 回滚事务
tranx.Rollback();
throw;
}
}
}
public void Delete(int commentUID)
{
using (IDBTaskTransaction tranx = MyDBTaskFactory.CreateDBTaskTransaction())
{
// 创建评论数据库任务
ICommentTask task = MyDBTaskFactory.CreateCommentTask();
// 创建评论扩展
ICommentExtension ext = MyExtensionFactory.CreateCommentExtension();
// 登记数据库事务
task.EnlistTransaction(tranx);
ext.EnlistTransactionObject(tranx);
// 设置活动用户名称
ext.Actor = this.Actor;
try
{
// 获取要删除的评论
Comment delComment = task.ViewComment(commentUID);
// 准备删除评论
ext.OnPreDelete(delComment);
// 删除评论
task.Delete(commentUID);
// 删除评论完成
ext.OnDeleteComplete(delComment);
// 提交事务
tranx.Commit();
}
catch
{
// 回滚事务
tranx.Rollback();
throw;
}
}
}
public IList<Comment> ViewCommentList(int belongToArticleUID)
{
IList<Comment> viewCommentList = null;
using (IDBTaskTransaction tranx = MyDBTaskFactory.CreateDBTaskTransaction())
{
// 创建评论数据库任务
ICommentTask task = MyDBTaskFactory.CreateCommentTask();
// 创建评论扩展
ICommentExtension ext = MyExtensionFactory.CreateCommentExtension();
// 登记数据库事务
task.EnlistTransaction(tranx);
ext.EnlistTransactionObject(tranx);
// 设置活动用户名称
ext.Actor = this.Actor;
try
{
// 准备浏览评论列表
ext.OnPreViewCommentList(belongToArticleUID);
// 浏览评论列表
viewCommentList = task.ViewCommentList(belongToArticleUID);
// 浏览评论列表完成
ext.OnViewCommentListComplete(belongToArticleUID, viewCommentList);
// 提交事务
tranx.Commit();
}
catch
{
// 回滚事务
tranx.Rollback();
throw;
}
}
return viewCommentList;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?