基于.Net平台的extjs单用户Blog系统

来源:互联网 发布:dell windows 10 下载 编辑:程序博客网 时间:2024/04/26 23:44

  这是通过Java版本的Wlr单用户Blog系统改写的系统,是一个基于ExtSJ技术实现的简单blog系统,演示了ExtJS的综合应用。

  系统后台使用.Net平台,语言为C#,技术构架为NHibernate+Spring.Net+Vifir实现,支持多种数据库,采用三层结构,数据访问层DAO、业务逻辑层及表示层完全分离。DAO层使用的泛型DAO,只需要一个DAO接口即可,不需要写具体的实现。

  系统演示:http://www.vifir.com/resources/records/codes/wlrblog-net/wlrblog-net.html

  系统下载地址:http://www.vifir.com/download/extblog-net.zip

  (备注:该代码仅供学习使用,也不是什么开源项目,只是一个演示ExtJS在.Net平台上使用的综合示例,下载的源码只有web层的部份,业务层已经封装到DLL中,可以使用VS2005(SP1)以上的版本打开,运行前先要建一个空的数据库,系统运行会自动根据域模型建表!)

  下面是系统后台的截图

  

  (登录)

  系统中的一些源码摘要:

  域模型:  

namespace Vifir.Model.Domain
{
public class Topic
{
private long id;

private string title;

private string content;

private string intro;

private TopicCategory category;

private IList<TopicComment> comments = new List<TopicComment>();

private DateTime inputTime = DateTime.Now;

private int readTimes = 0;
public virtual long Id
{
get { return id; }
set { id = value; }
}
public virtual string Title
{
get { return title; }
set { title = value; }
}
public virtual string Content
{
get { return content; }
set { content = value; }
}
public virtual string Intro
{
get { return intro; }
set { intro = value; }
}
public virtual TopicCategory Category
{
get { return category; }
set { category = value; }
}
public virtual IList<TopicComment> Comments
{
get { return comments; }
set { comments = value; }
}
public virtual DateTime InputTime
{
get { return inputTime; }
set { inputTime = value; }
}
public virtual int ReadTimes
{
get { return readTimes; }
set { readTimes = value; }
}
}
}

  DAO接口

namespace Vifir.Model.DAO
{
public interface ITopicDAO : GenericDAO
{
}
}

  泛型DAO配置

<object id="TopicDao" parent="abstractDao">
    <property name="proxyInterfaces" value="Vifir.Model.DAO.ITopicDAO"/>
    <property name="target">
      <object parent="baseDAO" type="Vifir.Core.GenericDAOImpl&lt;Vifir.Model.Domain.Topic>,Vifir.Core" />
    </property>
  </object>

  TopicService业务层实现代码

namespace Vifir.Model.Service.Impl
{
public class TopicServiceImpl:ITopicService
{
private ITopicDAO topicDao;

public ITopicDAO TopicDao
{
set { topicDao = value; }
}


public long addTopic(Topic topic) {
this.topicDao.Save(topic);
return topic.Id;
}

public Topic getTopic(long id) {
Topic topic = this.topicDao.Get(id);
return topic;
}

public bool delTopic(long id) {
Topic topic = this.getTopic(id);
if(topic.Comments.Count>0)throw new LogicException("该文章下还有评论,不能删除!");
if (topic != null) {
this.topicDao.Remove(id);
return true;
}
return false;
}


public IPageList getTopicBy(IQueryObject queryObject) {
return QueryUtil.query(queryObject, typeof(Topic),this.topicDao);
}

public bool updateTopic(long id, Topic topic) {
if (id != default(long))
{
topic.Id=id;
} else {
return false;
}
this.topicDao.Update(topic);
return true;
}
}
}

 Web层的添删改查代码:  

public partial class manage_Topic : BaseAction
{
private ITopicService service;
private ITopicCategoryService categoryService;
public ITopicService Service
{
set { service = value; }
}
public ITopicCategoryService CategoryService
{
set { categoryService = value; }
}

public void List()
{
QueryObject qo = new QueryObject();
ToPo(qo);
string categoryId = Request.Params["categoryId"];
if (categoryId != null && !"".Equals(categoryId))
{
qo.addQuery("obj.Category.id", long.Parse(categoryId), "=");
}
IPageList pageList = service.getTopicBy(qo);
jsonResult = pageList;
}

public void Remove()
{
long id = long.Parse(Request.Params["id"]);
service.delTopic(id);
jsonResult = true;
}

public void Save()
{
Topic obj = new Topic();
ToPo(obj);
string CategoryId = Request.Params["CategoryId"];
if (CategoryId != null && !"".Equals(CategoryId))
{
TopicCategory c = this.categoryService.getTopicCategory(long.Parse(CategoryId));
obj.Category = c;
}
if (!HasError())
service.addTopic(obj);
extFormResult = true;
}

public void Update()
{
long id = long.Parse(Request.Params["id"]);
Topic obj = service.getTopic(id);
ToPo(obj);
string CategoryId = Request.Params["CategoryId"];
if (CategoryId != null && !"".Equals(CategoryId))
{
TopicCategory c = this.categoryService.getTopicCategory(long.Parse(CategoryId));
obj.Category = c;
}
if (!HasError())
service.updateTopic(id, obj);
extFormResult = true;
}
}
  
原创粉丝点击