基於.Net平臺的extjs單用戶Blog系統發佈

這是用.net2.0開發的一個基於ExtSJ技術實現的簡單blog系統,演示了ExtJS的綜合應用。
  系統後臺使用.Net平臺,語言爲C#,技術構架爲NHibernate+Spring.Net+Vifir實現,支持多種數據庫,採用三層結構,數據訪問層DAO、業務邏輯層及表示層完全分離。DAO層使用的泛型DAO,只需要一個DAO接口即可,不需要寫具體的實現。
  系統演示:
  下面是系統後臺的截圖
  
  (登錄)
  系統中的一些源碼摘要:
域模型:
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;
    }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章