diff --git a/MyBlog/Blog.Domain/ArticelService.cs b/MyBlog/Blog.Domain/ArticelService.cs
index 9e07c82..2b823e2 100644
--- a/MyBlog/Blog.Domain/ArticelService.cs
+++ b/MyBlog/Blog.Domain/ArticelService.cs
@@ -1,337 +1,301 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Blog.Domain.Interface;
-using Blog.Repository.Interface;
-using Blog.Model;
-using System.Web;
-using System.Web.Caching;
-namespace Blog.Domain
-{
- ///
- /// 文章业务类
- ///
- public class ArticleService : IArticleService
- {
- ///
- /// 依赖注入赋值
- ///
- private IArticleRepository _articleRepository;
- private IRoleService _roleService;
- private ISettingService _settingService;
- private IUserService _userService;
- private ICategoryService _categoryService;
- public ArticleService(ICategoryService categoryService, IArticleRepository articleRepository, IRoleService roleService, ISettingService settingService, IUserService userService)
- {
- _userService = userService;
- _articleRepository = articleRepository;
- _roleService = roleService;
- _settingService = settingService;
- _categoryService = categoryService;
- }
-
- public int AddArticle(Model.Article article)
- {
-
- if (_roleService.AddArticlePower())
- {
- if (string.IsNullOrEmpty(article.Title))
- {
- throw new DomainException("Title", "文章标题不能为空!");
- }
- else if (string.IsNullOrEmpty(article.Content))
- {
- throw new DomainException("Content", "文章内容不能为空!");
- }
- else if (article.Categorys.Count == 0)
- {
- throw new DomainException("Category", "文章必须要有一个分类!");
- }
- article.Status = ArticleStatus.Open;
- article.Author = _userService.GetLoginUser();
- IList categorys = article.Categorys;
- article.Categorys = null;
- int id = _articleRepository.Add(article);
- article.Categorys = categorys;
- _articleRepository.Update(article);
- return id;
- }
- else
- {
- throw new DomainException("NoPower", "对不起,您没有权限添加文章。");
- }
- }
-
- public void UpdateArticle(Model.Article article)
- {
- Article article2 = _articleRepository.Get(article.ArticleId);
- if (article2 == null)
- {
- throw new DomainException("NoFind", "对不起,该文章不存在或已经被删除。");
- }
- if (!_roleService.EditArticlePower())
- {
- throw new DomainException("NoPower", "对不起,您没有权限编辑该文章。");
- }
- else
- {
- article.ModifyDate = DateTime.Now;
- _articleRepository.Update(article);
- }
- }
-
- public void DeleteArticle(int id)
- {
- Article article = _articleRepository.Get(id);
- if (article == null)
- {
- throw new DomainException("NoFind", "对不起,该文章不存在或已经被删除。");
- }
- if (_roleService.DeleteArticlePower())
- {
- _articleRepository.BeginTransaction();
- try
- {
- _articleRepository.Update("delete from Comment where ArticleId=" + id);
- _articleRepository.Update("delete from [Attach] where ArticleId=" + id);
- _articleRepository.Update("delete from CategoryRelationShip where ArticleId=" + id);
- _articleRepository.Update("delete from Article where ArticleId=" + id);
- foreach (var category in article.Categorys)
- {
- category.Count = category.Count - 1 >= 0 ? category.Count - 1 : 0;
- _categoryService.UpdateCategory(category);
- }
- }
- catch (Exception ex)
- {
- _articleRepository.RollbackTransaction();
- throw new DomainException("DatabaseError", ex.Message);
- }
- _articleRepository.CommitTransaction();
- }
- else
- {
- throw new DomainException("NoPower", "对不起,您没有权限删除该文章。");
- }
- }
-
- public Model.Article GetArticle(int id)
- {
- Article article = (Article)HttpRuntime.Cache.Get("Article_" + id);
- if (article != null)
- return article;
- article = _articleRepository.Get(id);
- if (article == null)
- {
- throw new DomainException("NoFind", "对不起,该文章不存在或已经被删除。");
- }
- HttpRuntime.Cache.Insert("Article_" + id, article, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds(30));
- return article;
- }
-
- public PageInfo FindArticleByTitle(string title, int pageIndex)
- {
- int pageSize = int.Parse(_settingService.GetSetting("ArticlePageSize"));
- PageInfo pageInfo = new PageInfo();
- pageInfo.PageSize = pageSize;
-
- int totalItem = (int)_articleRepository.Single(
- qeruy => qeruy
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Title.Contains(title))
- .Count()
- );
-
- pageInfo.TotalItem = totalItem;
- pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
-
- IList list = _articleRepository.Find(
- Query => Query
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Title.Contains(title))
- .OrderByDescending(a => a.CreateDate)
- .Skip((pageIndex - 1) * pageSize).Take(pageSize)
- );
-
- pageInfo.PageItems = list;
- pageInfo.PageIndex = pageIndex;
-
- return pageInfo;
- }
-
- public PageInfo GetArticleByCategory(int categoryId, int pageIndex)
- {
- PageInfo articles = (PageInfo)HttpRuntime.Cache.Get("Article_Category" + categoryId + "_" + pageIndex);
- if (articles != null)
- return articles;
- int pageSize = int.Parse(_settingService.GetSetting("ArticlePageSize"));
- PageInfo pageInfo = new PageInfo();
- pageInfo.PageSize = pageSize;
- int totalItem = (int)_articleRepository.Single(
- qeruy => qeruy
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Categorys.Where(c => c.CategoryId == categoryId).Count() > 0)
- .Count()
- );
- pageInfo.TotalItem = totalItem;
- pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
-
- IList list = _articleRepository.Find(
- Query => Query
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Categorys.Where(c => c.CategoryId == categoryId).Count() > 0)
- .OrderByDescending(a => a.CreateDate)
- .Skip((pageIndex - 1) * pageSize).Take(pageSize)
- );
- pageInfo.PageItems = list;
- pageInfo.PageIndex = pageIndex;
- HttpRuntime.Cache.Insert("Article_Category" + categoryId + "_" + pageIndex, pageInfo, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds(30));
- return pageInfo;
- }
-
- public PageInfo FindArticleByMonth(DateTime month, int pageIndex)
- {
-
- PageInfo articles = (PageInfo)HttpRuntime.Cache.Get("Article_month" + month + "_" + pageIndex);
- if (articles != null)
- return articles;
- int pageSize = int.Parse(_settingService.GetSetting("ArticlePageSize"));
-
- PageInfo pageInfo = new PageInfo();
- pageInfo.PageSize = pageSize;
-
- int totalItem = (int)_articleRepository.Single(
- qeruy => qeruy
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Year == month.Year && a.CreateDate.Month == month.Month)
- .Count()
- );
- pageInfo.TotalItem = totalItem;
- pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
-
- IList list = _articleRepository.Find(
- Query => Query
- .Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Year == month.Year && a.CreateDate.Month == month.Month)
- );
- pageInfo.PageItems = list;
- pageInfo.PageIndex = pageIndex;
- HttpRuntime.Cache.Insert("Article_month" + month + "_" + pageIndex, pageInfo, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds(30));
- return pageInfo;
- }
-
- public PageInfo FindArticleByDay(DateTime day, int pageIndex)
- {
-
- PageInfo articles = (PageInfo)HttpRuntime.Cache.Get("Article_day" + day + "_" + pageIndex);
- if (articles != null)
- return articles;
-
- int pageSize = int.Parse(_settingService.GetSetting("ArticlePageSize"));
- PageInfo pageInfo = new PageInfo();
- pageInfo.PageSize = pageSize;
- int totalItem = (int)_articleRepository.Single(
- qeruy => qeruy
- .Where(
- a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Day == day.Day && a.CreateDate.Month == day.Month && a.CreateDate.Year == day.Year
- )
- .Count()
- );
- pageInfo.TotalItem = totalItem;
- pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
-
- IList list = _articleRepository.Find(
- query => query.Where(
- a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Day == day.Day && a.CreateDate.Month == day.Month && a.CreateDate.Year == day.Year
- )
- .OrderByDescending(a => a.CreateDate)
- .Skip((pageIndex - 1) * pageSize).Take(pageSize)
- );
- pageInfo.PageItems = list;
- pageInfo.PageIndex = pageIndex;
- HttpRuntime.Cache.Insert("Article_day" + day + "_" + pageIndex, pageInfo, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds(30));
- return pageInfo;
- }
-
-
- public IList GetLastBlog()
- {
- IList LastBlog = (IList)HttpRuntime.Cache.Get("Article_LastBlog");
- if (LastBlog != null)
- {
- return LastBlog;
- }
- int count = int.Parse(_settingService.GetSetting("LastArticleCount"));
- LastBlog = _articleRepository.Find(
- query => query.Where(
- a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open
- )
- .OrderByDescending(a => a.CreateDate)
- .Take(count)
- );
- HttpRuntime.Cache.Insert("Article_LastBlog", LastBlog, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromMinutes(1));
- return LastBlog;
- }
-
-
- public IList GetLastPage()
- {
- IList LastPage = (IList)HttpRuntime.Cache.Get("Article_LastPage");
- if (LastPage != null)
- {
- return LastPage;
- }
- int count = int.Parse(_settingService.GetSetting("LastArticleCount"));
- LastPage = _articleRepository.Find(
- query => query.Where(
- a => a.Type == ArticleType.Page && a.Status == ArticleStatus.Open
- )
- .OrderByDescending(a => a.CreateDate)
- .Take(count)
- );
- HttpRuntime.Cache.Insert("Article_LastPage", LastPage, new SqlCacheDependency("Default", "Article"), DateTime.MaxValue, TimeSpan.FromMinutes(1));
- return LastPage;
- }
-
- public Article BrowseArticle(int articleId)
- {
- Article article = GetArticle(articleId);
-
- if (article.Status == ArticleStatus.Delete)
- {
- throw new DomainException("NoFind", "对不起,该文章不存在或已经被删除。");
- }
- else if (_roleService.ReadArticelPower(article))
- {
- article.Browse++;
- _articleRepository.Update(article);
- //_articleRepository.Update("update Article set Browse=" + (article.Browse + 1) + " where ArticleId=" + articleId);
- return article;
- }
- else
- {
- throw new DomainException("NoPower", "对不起,您没有权限查看该文章。");
- }
- }
-
- public PageInfo FindArticlesByQuery(Func, IQueryable> expr, int pageIndex, int pageSize)
- {
- if (!_roleService.AddArticlePower())
- {
- throw new DomainException("NoPower", "对不起,您没有权限!");
- }
-
- pageIndex = pageIndex > 0 ? pageIndex : 1;
-
- int count = (int)_articleRepository.Single(query => expr(query).Count());
-
- PageInfo info = new PageInfo() { PageIndex = pageIndex, PageSize = pageSize, TotalItem = count };
- info.PageIndex = info.PageIndex > info.TotalPage ? info.TotalPage : info.PageIndex;
-
- IList list = _articleRepository.Find(query => expr(query).Skip((pageIndex - 1) * pageSize).Take(pageSize));
-
- info.PageItems = list;
- return info;
- }
-
-
- public object GetArticleSingle(Func, object> expr)
- {
- return _articleRepository.Single(expr);
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Blog.Domain.Interface;
+using Blog.Repository.Interface;
+using Blog.Model;
+using System.Web;
+using System.Web.Caching;
+
+namespace Blog.Domain
+{
+ ///
+ /// 文章业务类
+ ///
+ public class ArticleService : IArticleService
+ {
+ ///
+ /// 依赖注入赋值
+ ///
+ private IArticleRepository _articleRepository;
+ private IRoleService _roleService;
+ private ISettingService _settingService;
+ private IUserService _userService;
+ private ICategoryService _categoryService;
+
+ public ArticleService (ICategoryService categoryService, IArticleRepository articleRepository, IRoleService roleService, ISettingService settingService, IUserService userService)
+ {
+ _userService = userService;
+ _articleRepository = articleRepository;
+ _roleService = roleService;
+ _settingService = settingService;
+ _categoryService = categoryService;
+ }
+
+ public int AddArticle (Model.Article article)
+ {
+
+ if (_roleService.AddArticlePower ()) {
+ if (string.IsNullOrEmpty (article.Title)) {
+ throw new DomainException ("Title", "文章标题不能为空!");
+ } else if (string.IsNullOrEmpty (article.Content)) {
+ throw new DomainException ("Content", "文章内容不能为空!");
+ } else if (article.Categorys.Count == 0) {
+ throw new DomainException ("Category", "文章必须要有一个分类!");
+ }
+ article.Status = ArticleStatus.Open;
+ article.Author = _userService.GetLoginUser ();
+ IList categorys = article.Categorys;
+ article.Categorys = null;
+ int id = _articleRepository.Add (article);
+ article.Categorys = categorys;
+ _articleRepository.Update (article);
+ return id;
+ } else {
+ throw new DomainException ("NoPower", "对不起,您没有权限添加文章。");
+ }
+ }
+
+ public void UpdateArticle (Model.Article article)
+ {
+ Article article2 = _articleRepository.Get (article.ArticleId);
+ if (article2 == null) {
+ throw new DomainException ("NoFind", "对不起,该文章不存在或已经被删除。");
+ }
+ if (!_roleService.EditArticlePower ()) {
+ throw new DomainException ("NoPower", "对不起,您没有权限编辑该文章。");
+ } else {
+ article.ModifyDate = DateTime.Now;
+ _articleRepository.Update (article);
+ }
+ }
+
+ public void DeleteArticle (int id)
+ {
+ Article article = _articleRepository.Get (id);
+ if (article == null) {
+ throw new DomainException ("NoFind", "对不起,该文章不存在或已经被删除。");
+ }
+ if (_roleService.DeleteArticlePower ()) {
+ _articleRepository.BeginTransaction ();
+ try {
+ _articleRepository.Update ("delete from Comment where ArticleId=" + id);
+ _articleRepository.Update ("delete from Attach where ArticleId=" + id);
+ _articleRepository.Update ("delete from CategoryRelationShip where ArticleId=" + id);
+ _articleRepository.Update ("delete from Article where ArticleId=" + id);
+ foreach (var category in article.Categorys) {
+ category.Count = category.Count - 1 >= 0 ? category.Count - 1 : 0;
+ _categoryService.UpdateCategory (category);
+ }
+ } catch (Exception ex) {
+ _articleRepository.RollbackTransaction ();
+ throw new DomainException ("DatabaseError", ex.Message);
+ }
+ _articleRepository.CommitTransaction ();
+ } else {
+ throw new DomainException ("NoPower", "对不起,您没有权限删除该文章。");
+ }
+ }
+
+ public Model.Article GetArticle (int id)
+ {
+ Article article = (Article)HttpRuntime.Cache.Get ("Article_" + id);
+ if (article != null)
+ return article;
+ article = _articleRepository.Get (id);
+ if (article == null) {
+ throw new DomainException ("NoFind", "对不起,该文章不存在或已经被删除。");
+ }
+ HttpRuntime.Cache.Insert ("Article_" + id, article, new SqlCacheDependency ("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds (30));
+ return article;
+ }
+
+ public PageInfo FindArticleByTitle (string title, int pageIndex)
+ {
+ int pageSize = int.Parse (_settingService.GetSetting ("ArticlePageSize"));
+ PageInfo pageInfo = new PageInfo ();
+ pageInfo.PageSize = pageSize;
+
+ int totalItem = (int)_articleRepository.Single (
+ qeruy => qeruy
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Title.Contains (title))
+ .Count ()
+ );
+
+ pageInfo.TotalItem = totalItem;
+ pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
+ pageIndex = pageIndex <= 0 ? 1 : pageIndex;
+ IList list = _articleRepository.Find (
+ Query => Query
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Title.Contains (title))
+ .OrderByDescending (a => a.CreateDate)
+ .Skip ((pageIndex - 1) * pageSize).Take (pageSize)
+ );
+
+ pageInfo.PageItems = list;
+ pageInfo.PageIndex = pageIndex;
+
+ return pageInfo;
+ }
+
+ public PageInfo GetArticleByCategory (int categoryId, int pageIndex)
+ {
+ PageInfo articles = (PageInfo)HttpRuntime.Cache.Get ("Article_Category" + categoryId + "_" + pageIndex);
+ if (articles != null)
+ return articles;
+ int pageSize = int.Parse (_settingService.GetSetting ("ArticlePageSize"));
+ PageInfo pageInfo = new PageInfo ();
+ pageInfo.PageSize = pageSize;
+ int totalItem = (int)_articleRepository.Single (
+ qeruy => qeruy
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Categorys.Where (c => c.CategoryId == categoryId).Count () > 0)
+ .Count ()
+ );
+ pageInfo.TotalItem = totalItem;
+ pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
+
+ IList list = _articleRepository.Find (
+ Query => Query
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.Categorys.Where (c => c.CategoryId == categoryId).Count () > 0)
+ .OrderByDescending (a => a.CreateDate)
+ .Skip ((pageIndex - 1) * pageSize).Take (pageSize)
+ );
+ pageInfo.PageItems = list;
+ pageInfo.PageIndex = pageIndex;
+ HttpRuntime.Cache.Insert ("Article_Category" + categoryId + "_" + pageIndex, pageInfo, new SqlCacheDependency ("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds (30));
+ return pageInfo;
+ }
+
+ public PageInfo FindArticleByMonth (DateTime month, int pageIndex)
+ {
+ int pageSize = int.Parse (_settingService.GetSetting ("ArticlePageSize"));
+
+ PageInfo pageInfo = new PageInfo ();
+ pageInfo.PageSize = pageSize;
+
+ int totalItem = (int)_articleRepository.Single (
+ qeruy => qeruy
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Year == month.Year && a.CreateDate.Month == month.Month)
+ .Count ()
+ );
+ pageInfo.TotalItem = totalItem;
+ pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
+ pageIndex = pageIndex <= 0 ? 1 : pageIndex;
+ IList list = _articleRepository.Find (
+ Query => Query
+ .Where (a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Year == month.Year && a.CreateDate.Month == month.Month)
+ );
+ pageInfo.PageItems = list;
+ pageInfo.PageIndex = pageIndex;
+ return pageInfo;
+ }
+
+ public PageInfo FindArticleByDay (DateTime day, int pageIndex)
+ {
+
+ PageInfo articles = (PageInfo)HttpRuntime.Cache.Get ("Article_day" + day + "_" + pageIndex);
+ if (articles != null)
+ return articles;
+
+ int pageSize = int.Parse (_settingService.GetSetting ("ArticlePageSize"));
+ PageInfo pageInfo = new PageInfo ();
+ pageInfo.PageSize = pageSize;
+ int totalItem = (int)_articleRepository.Single (
+ qeruy => qeruy
+ .Where (
+ a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Day == day.Day && a.CreateDate.Month == day.Month && a.CreateDate.Year == day.Year
+ )
+ .Count ()
+ );
+ pageInfo.TotalItem = totalItem;
+ pageIndex = pageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : pageIndex;
+
+ IList list = _articleRepository.Find (
+ query => query.Where (
+ a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open && a.CreateDate.Day == day.Day && a.CreateDate.Month == day.Month && a.CreateDate.Year == day.Year
+ )
+ .OrderByDescending (a => a.CreateDate)
+ .Skip ((pageIndex - 1) * pageSize).Take (pageSize)
+ );
+ pageInfo.PageItems = list;
+ pageInfo.PageIndex = pageIndex;
+ HttpRuntime.Cache.Insert ("Article_day" + day + "_" + pageIndex, pageInfo, new SqlCacheDependency ("Default", "Article"), DateTime.MaxValue, TimeSpan.FromSeconds (30));
+ return pageInfo;
+ }
+
+ public IList GetLastBlog ()
+ {
+ IList LastBlog = null;
+ int count = int.Parse (_settingService.GetSetting ("LastArticleCount"));
+ LastBlog = _articleRepository.Find (
+ query => query.Where (
+ a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open
+ )
+ .OrderByDescending (a => a.CreateDate)
+ .Take (count)
+ );
+ return LastBlog;
+ }
+
+ public IList GetLastPage ()
+ {
+ IList LastPage = (IList)HttpRuntime.Cache.Get ("Article_LastPage");
+ if (LastPage != null) {
+ return LastPage;
+ }
+ int count = int.Parse (_settingService.GetSetting ("LastArticleCount"));
+ LastPage = _articleRepository.Find (
+ query => query.Where (
+ a => a.Type == ArticleType.Page && a.Status == ArticleStatus.Open
+ )
+ .OrderByDescending (a => a.CreateDate)
+ .Take (count)
+ );
+ HttpRuntime.Cache.Insert ("Article_LastPage", LastPage, new SqlCacheDependency ("Default", "Article"), DateTime.MaxValue, TimeSpan.FromMinutes (1));
+ return LastPage;
+ }
+
+ public Article BrowseArticle (int articleId)
+ {
+ Article article = GetArticle (articleId);
+
+ if (article.Status == ArticleStatus.Delete) {
+ throw new DomainException ("NoFind", "对不起,该文章不存在或已经被删除。");
+ } else if (_roleService.ReadArticelPower (article)) {
+ article.Browse++;
+ _articleRepository.Update (article);
+ return article;
+ } else {
+ throw new DomainException ("NoPower", "对不起,您没有权限查看该文章。");
+ }
+ }
+
+ public PageInfo FindArticlesByQuery (Func, IQueryable> expr, int pageIndex, int pageSize)
+ {
+ if (!_roleService.AddArticlePower ()) {
+ throw new DomainException ("NoPower", "对不起,您没有权限!");
+ }
+
+ pageIndex = pageIndex > 0 ? pageIndex : 1;
+
+ int count = (int)_articleRepository.Single (query => expr (query).Count ());
+
+ PageInfo info = new PageInfo () {
+ PageIndex = pageIndex,
+ PageSize = pageSize,
+ TotalItem = count
+ };
+ info.PageIndex = info.PageIndex > info.TotalPage ? info.TotalPage : info.PageIndex;
+
+ IList list = _articleRepository.Find (query => expr (query).Skip ((pageIndex - 1) * pageSize).Take (pageSize));
+
+ info.PageItems = list;
+ return info;
+ }
+
+ public object GetArticleSingle (Func, object> expr)
+ {
+ return _articleRepository.Single (expr);
+ }
+ }
+}
diff --git a/MyBlog/Blog.Domain/Blog.Domain.csproj b/MyBlog/Blog.Domain/Blog.Domain.csproj
index 0a3698f..5bf5ba8 100644
--- a/MyBlog/Blog.Domain/Blog.Domain.csproj
+++ b/MyBlog/Blog.Domain/Blog.Domain.csproj
@@ -12,6 +12,8 @@
v4.0
512
+ 12.0.0
+ 2.0
true
@@ -66,11 +68,11 @@
- {2ec57ecb-8b69-42fc-b11b-5ef3223d182e}
+ {2EC57ECB-8B69-42FC-B11B-5EF3223D182E}
Blog.Model
- {7a88f526-8e70-4385-aeb2-fea874ac0814}
+ {7A88F526-8E70-4385-AEB2-FEA874AC0814}
Blog.Repository
diff --git a/MyBlog/Blog.Domain/CommentService.cs b/MyBlog/Blog.Domain/CommentService.cs
index 44db034..916a96d 100644
--- a/MyBlog/Blog.Domain/CommentService.cs
+++ b/MyBlog/Blog.Domain/CommentService.cs
@@ -1,311 +1,311 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Blog.Domain.Interface;
-using Blog.Repository.Interface;
-using Blog.Model;
-using System.Web;
-using System.Web.Caching;
-namespace Blog.Domain
-{
- ///
- /// 评论服务实现
- ///
- public class CommentService : ICommentService
- {
- ///
- /// 依赖注入
- ///
- private ICommentRepository _commentRepository;
- private IArticleService _articleService;
- private ISessionManager _sessionManager;
- private IRoleService _roleService;
- private ISettingService _settiongService;
-
- public CommentService(IArticleService articleService, ICommentRepository commentRepository, ISessionManager sessionManger, IRoleService roleService, ISettingService settiongService)
- {
- _articleService = articleService;
- _commentRepository = commentRepository;
- _sessionManager = sessionManger;
- _roleService = roleService;
- _settiongService = settiongService;
- }
-
- ///
- /// 取得最新评论
- ///
- ///
- public IList GetLastComments()
- {
- //缓存加载
- IList comments = (IList)HttpRuntime.Cache.Get("Comment_LastComment");
-
- if (comments != null)
- {
- return comments;
- }
- int count = int.Parse(_settiongService.GetSetting("LastCommentCount"));
- comments = _commentRepository.Find(
- query => query.Where(
- c => c.Status == CommentStatus.Open
- )
- .OrderByDescending(c => c.CreateDate).Take(count)
- );
-
- //加入缓存
- HttpRuntime.Cache.Insert("Comment_LastComment", comments, new SqlCacheDependency("Default", "Comment"), DateTime.UtcNow.AddMinutes(1), TimeSpan.Zero);
- return comments;
- }
-
- ///
- /// 取得一个文章的评论
- ///
- ///
- ///
- ///
- public PageInfo GetCommentsByArticleId(int articleId, int pageIndex)
- {
- //缓存加载
- PageInfo page = (PageInfo)HttpRuntime.Cache.Get("Comment_ArticlePage" + articleId + "_" + pageIndex);
-
- if (page != null)
- {
- return page;
- }
-
- page = new PageInfo();
- int userId = _sessionManager.User == null ? 0 : _sessionManager.User.UserId;
- int pageSize = int.Parse(_settiongService.GetSetting("CommentPageSize"));
- page.PageSize = pageSize;
-
- page.TotalItem = (int)_commentRepository.Single(query => query.Where(
- c => c.Article.ArticleId == articleId && (c.Parent.CommentId == 0 || c.Parent == null) && ((c.Status == CommentStatus.Open) || (c.User.UserId == userId && c.Status != CommentStatus.Delete))
- ).Count()
- );
-
- pageIndex = pageIndex > page.TotalPage ? page.TotalPage : pageIndex;
-
- page.PageItems = _commentRepository.Find(query => query.Where(
- c => c.Article.ArticleId == articleId && (c.Parent.CommentId == 0 || c.Parent == null) && ((c.Status == CommentStatus.Open) || (c.User.UserId == userId && c.Status != CommentStatus.Delete))
- ).OrderBy(c => c.CreateDate).Skip((pageIndex - 1) * pageSize).Take(pageSize)
- );
-
-
- page.PageIndex = pageIndex;
-
- ///加入缓存
- HttpRuntime.Cache.Insert("Comment_ArticlePage" + articleId + "_" + pageIndex, page, new SqlCacheDependency("Default", "Comment"), DateTime.UtcNow.AddMilliseconds(30), TimeSpan.Zero);
- return page;
- }
-
- ///
- /// 添加评论
- ///
- ///
- ///
- public int AddComment(Comment comment)
- {
- if (!_roleService.AddCommentPower())
- {
- throw new DomainException("NoPower", "对不起,您没有权限发表评论。");
- }
- else
- {
- if (_sessionManager.User == null)
- {
- if (string.IsNullOrEmpty(comment.Author))
- {
- throw new DomainException("NoAuthor", "对不起,需要填写昵称才能发表评论。");
- }
- else if (string.IsNullOrEmpty(comment.AuthorMail))
- {
- throw new DomainException("NoAuthor", "对不起,需要填写邮箱才能发表评论。");
- }
- }
- else
- {
- comment.User = _sessionManager.User;
- comment.Author = comment.User.UserName;
- comment.AuthorMail = comment.User.Email;
- }
- int id = 0;
- try
- {
- //打开事务
- _commentRepository.BeginTransaction();
-
- //取得评论所在文章
- comment.Article = _articleService.GetArticle(comment.Article.ArticleId);
-
- //如果父评论不为空,而且父评论的文章ID跟当前的文章ID不一致,抛出异常
- if (comment.Parent != null && comment.Article.ArticleId != comment.Parent.Article.ArticleId)
- {
- throw new DomainException("DataError", "对不起,您提交的数据异常!");
- }
- //检查镶套层数
- CheckCommentLevel(comment);
-
- //给文章添加评论个数
- comment.Article.CommentCount++;
-
- //评论的创建时间
- comment.CreateDate = DateTime.Now;
-
- //评论默认状态
- if (_roleService.AddArticlePower())
- {
- comment.Status = CommentStatus.Open;
- }
- else
- {
- comment.Status = int.Parse(_settiongService.GetSetting("CommentSatus"));
- }
-
- //添加文章
- id = _commentRepository.Add(comment);
-
- //事务提交
- _commentRepository.CommitTransaction();
- }
- catch (Exception ex)
- {
- //回滚事务
- _commentRepository.RollbackTransaction();
- throw ex;
- }
- return id;
- }
- }
-
- ///
- /// 取得父评论下的子评论
- ///
- ///
- ///
- public IList GetCommentsByParentId(int pid)
- {
- return _commentRepository.Find(query => query.Where(c => c.Parent.CommentId == pid));
- }
-
- ///
- /// 取得某一个评论
- ///
- ///
- ///
- public Comment GetComment(int id)
- {
- Comment comment = _commentRepository.Get(id);
- if (comment == null)
- {
- throw new DomainException("NoFind", "没有找到该评论!");
- }
- return comment;
- }
-
-
- ///
- /// 取得评论的所在页数。 队长:“注意,前方高能!”
- ///
- ///
- ///
- public int GetCommentPageIndex(int commentId)
- {
- //缓存开启
- int? pageIndex = (int?)HttpRuntime.Cache.Get("Comment_PageIndex" + commentId);
-
- if (pageIndex != null)
- {
- return pageIndex.Value;
- }
- Comment comment = _commentRepository.Get(commentId);
-
- while (comment.Parent != null)
- {
- comment = comment.Parent;
- }
-
- int count = (int)_commentRepository.Single(
- query => query
- .Where(c => (c.Article.ArticleId == comment.Article.ArticleId) && (c.CreateDate <= comment.CreateDate) && (c.Parent.CommentId == 0 || c.Parent == null))
- .Count()
- );
- int pageSize = int.Parse(_settiongService.GetSetting("CommentPageSize"));
-
- pageIndex = (int)Math.Ceiling(count / (double)pageSize);
-
- //加入缓存
- HttpRuntime.Cache.Insert("Comment_PageIndex" + commentId, pageIndex, new SqlCacheDependency("Default", "Comment"), DateTime.MaxValue, TimeSpan.FromMinutes(1));
- return pageIndex.Value;
- }
-
- ///
- /// 检查评论层数是否过多
- ///
- ///
- private void CheckCommentLevel(Comment comment)
- {
- int i = 0;
- int maxReComment = int.Parse(_settiongService.GetSetting("MaxReComment"));
- Comment parent = comment.Parent;
-
- while (true)
- {
- if (parent == null || parent.Parent == null)
- {
- break;
- }
- parent = parent.Parent;
- i++;
-
- if (i >= maxReComment)
- {
- throw new DomainException("ReComment", "抱歉,评论最多只能镶套" + maxReComment + "层。");
- }
- }
- }
-
-
- public object GetCommentSingle(Func, object> expr)
- {
- if (_roleService.AdminPower())
- {
- new DomainException("NoPower", "对不起,没有权限!");
- }
- return _commentRepository.Single(expr);
- }
-
-
- public int GetVerifyCommentCount()
- {
- return (int)_commentRepository.Single(query => query.Where(c => c.Status == CommentStatus.Verify).Count());
- }
-
-
- public IList Find(Func, IQueryable> expr)
- {
- return _commentRepository.Find(expr);
- }
-
- public object Single(Func, object> expr)
- {
- return _commentRepository.Single(expr);
- }
-
-
- public void DeleteComment(int commentId)
- {
- Comment comment = GetComment(commentId);
- Article article = _articleService.GetArticle(comment.Article.ArticleId);
- article.CommentCount--;
- _articleService.UpdateArticle(article);
- _commentRepository.Delete(comment.CommentId);
- }
-
-
- public void UpdateComment(Comment comment)
- {
- _commentRepository.Update(comment);
- }
- }
-
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Blog.Domain.Interface;
+using Blog.Repository.Interface;
+using Blog.Model;
+using System.Web;
+using System.Web.Caching;
+namespace Blog.Domain
+{
+ ///
+ /// 评论服务实现
+ ///
+ public class CommentService : ICommentService
+ {
+ ///
+ /// 依赖注入
+ ///
+ private ICommentRepository _commentRepository;
+ private IArticleService _articleService;
+ private ISessionManager _sessionManager;
+ private IRoleService _roleService;
+ private ISettingService _settiongService;
+
+ public CommentService(IArticleService articleService, ICommentRepository commentRepository, ISessionManager sessionManger, IRoleService roleService, ISettingService settiongService)
+ {
+ _articleService = articleService;
+ _commentRepository = commentRepository;
+ _sessionManager = sessionManger;
+ _roleService = roleService;
+ _settiongService = settiongService;
+ }
+
+ ///
+ /// 取得最新评论
+ ///
+ ///
+ public IList GetLastComments()
+ {
+ //缓存加载
+ IList comments = (IList)HttpRuntime.Cache.Get("Comment_LastComment");
+
+ if (comments != null)
+ {
+ return comments;
+ }
+ int count = int.Parse(_settiongService.GetSetting("LastCommentCount"));
+ comments = _commentRepository.Find(
+ query => query.Where(
+ c => c.Status == CommentStatus.Open
+ )
+ .OrderByDescending(c => c.CreateDate).Take(count)
+ );
+
+ //加入缓存
+ HttpRuntime.Cache.Insert("Comment_LastComment", comments, new SqlCacheDependency("Default", "Comment"), DateTime.UtcNow.AddMinutes(1), TimeSpan.Zero);
+ return comments;
+ }
+
+ ///
+ /// 取得一个文章的评论
+ ///
+ ///
+ ///
+ ///
+ public PageInfo GetCommentsByArticleId(int articleId, int pageIndex)
+ {
+ //缓存加载
+ PageInfo page = (PageInfo)HttpRuntime.Cache.Get("Comment_ArticlePage" + articleId + "_" + pageIndex);
+
+ if (page != null)
+ {
+ return page;
+ }
+
+ page = new PageInfo();
+ int userId = _sessionManager.User == null ? 0 : _sessionManager.User.UserId;
+ int pageSize = int.Parse(_settiongService.GetSetting("CommentPageSize"));
+ page.PageSize = pageSize;
+
+ page.TotalItem = (int)_commentRepository.Single(query => query.Where(
+ c => c.Article.ArticleId == articleId && (c.Parent.CommentId == 0 || c.Parent == null) && ((c.Status == CommentStatus.Open) || (c.User.UserId == userId && c.Status != CommentStatus.Delete))
+ ).Count()
+ );
+
+ pageIndex = pageIndex > page.TotalPage ? page.TotalPage : pageIndex;
+ pageIndex = pageIndex <= 0 ? 1 : pageIndex;
+ page.PageItems = _commentRepository.Find(query => query.Where(
+ c => c.Article.ArticleId == articleId && (c.Parent.CommentId == 0 || c.Parent == null) && ((c.Status == CommentStatus.Open) || (c.User.UserId == userId && c.Status != CommentStatus.Delete))
+ ).OrderBy(c => c.CreateDate).Skip((pageIndex - 1) * pageSize).Take(pageSize)
+ );
+
+
+ page.PageIndex = pageIndex;
+
+ ///加入缓存
+ HttpRuntime.Cache.Insert("Comment_ArticlePage" + articleId + "_" + pageIndex, page, new SqlCacheDependency("Default", "Comment"), DateTime.UtcNow.AddMilliseconds(30), TimeSpan.Zero);
+ return page;
+ }
+
+ ///
+ /// 添加评论
+ ///
+ ///
+ ///
+ public int AddComment(Comment comment)
+ {
+ if (!_roleService.AddCommentPower())
+ {
+ throw new DomainException("NoPower", "对不起,您没有权限发表评论。");
+ }
+ else
+ {
+ if (_sessionManager.User == null)
+ {
+ if (string.IsNullOrEmpty(comment.Author))
+ {
+ throw new DomainException("NoAuthor", "对不起,需要填写昵称才能发表评论。");
+ }
+ else if (string.IsNullOrEmpty(comment.AuthorMail))
+ {
+ throw new DomainException("NoAuthor", "对不起,需要填写邮箱才能发表评论。");
+ }
+ }
+ else
+ {
+ comment.User = _sessionManager.User;
+ comment.Author = comment.User.UserName;
+ comment.AuthorMail = comment.User.Email;
+ }
+ int id = 0;
+ try
+ {
+ //打开事务
+ _commentRepository.BeginTransaction();
+
+ //取得评论所在文章
+ comment.Article = _articleService.GetArticle(comment.Article.ArticleId);
+
+ //如果父评论不为空,而且父评论的文章ID跟当前的文章ID不一致,抛出异常
+ if (comment.Parent != null && comment.Article.ArticleId != comment.Parent.Article.ArticleId)
+ {
+ throw new DomainException("DataError", "对不起,您提交的数据异常!");
+ }
+ //检查镶套层数
+ CheckCommentLevel(comment);
+
+ //给文章添加评论个数
+ comment.Article.CommentCount++;
+
+ //评论的创建时间
+ comment.CreateDate = DateTime.Now;
+
+ //评论默认状态
+ if (_roleService.AddArticlePower())
+ {
+ comment.Status = CommentStatus.Open;
+ }
+ else
+ {
+ comment.Status = int.Parse(_settiongService.GetSetting("CommentSatus"));
+ }
+
+ //添加文章
+ id = _commentRepository.Add(comment);
+
+ //事务提交
+ _commentRepository.CommitTransaction();
+ }
+ catch (Exception ex)
+ {
+ //回滚事务
+ _commentRepository.RollbackTransaction();
+ throw ex;
+ }
+ return id;
+ }
+ }
+
+ ///
+ /// 取得父评论下的子评论
+ ///
+ ///
+ ///
+ public IList GetCommentsByParentId(int pid)
+ {
+ return _commentRepository.Find(query => query.Where(c => c.Parent.CommentId == pid));
+ }
+
+ ///
+ /// 取得某一个评论
+ ///
+ ///
+ ///
+ public Comment GetComment(int id)
+ {
+ Comment comment = _commentRepository.Get(id);
+ if (comment == null)
+ {
+ throw new DomainException("NoFind", "没有找到该评论!");
+ }
+ return comment;
+ }
+
+
+ ///
+ /// 取得评论的所在页数。 队长:“注意,前方高能!”
+ ///
+ ///
+ ///
+ public int GetCommentPageIndex(int commentId)
+ {
+ //缓存开启
+ int? pageIndex = (int?)HttpRuntime.Cache.Get("Comment_PageIndex" + commentId);
+
+ if (pageIndex != null)
+ {
+ return pageIndex.Value;
+ }
+ Comment comment = _commentRepository.Get(commentId);
+
+ while (comment.Parent != null)
+ {
+ comment = comment.Parent;
+ }
+
+ int count = (int)_commentRepository.Single(
+ query => query
+ .Where(c => (c.Article.ArticleId == comment.Article.ArticleId) && (c.CreateDate <= comment.CreateDate) && (c.Parent.CommentId == 0 || c.Parent == null))
+ .Count()
+ );
+ int pageSize = int.Parse(_settiongService.GetSetting("CommentPageSize"));
+
+ pageIndex = (int)Math.Ceiling(count / (double)pageSize);
+
+ //加入缓存
+ HttpRuntime.Cache.Insert("Comment_PageIndex" + commentId, pageIndex, new SqlCacheDependency("Default", "Comment"), DateTime.MaxValue, TimeSpan.FromMinutes(1));
+ return pageIndex.Value;
+ }
+
+ ///
+ /// 检查评论层数是否过多
+ ///
+ ///
+ private void CheckCommentLevel(Comment comment)
+ {
+ int i = 0;
+ int maxReComment = int.Parse(_settiongService.GetSetting("MaxReComment"));
+ Comment parent = comment.Parent;
+
+ while (true)
+ {
+ if (parent == null || parent.Parent == null)
+ {
+ break;
+ }
+ parent = parent.Parent;
+ i++;
+
+ if (i >= maxReComment)
+ {
+ throw new DomainException("ReComment", "抱歉,评论最多只能镶套" + maxReComment + "层。");
+ }
+ }
+ }
+
+
+ public object GetCommentSingle(Func, object> expr)
+ {
+ if (_roleService.AdminPower())
+ {
+ new DomainException("NoPower", "对不起,没有权限!");
+ }
+ return _commentRepository.Single(expr);
+ }
+
+
+ public int GetVerifyCommentCount()
+ {
+ return (int)_commentRepository.Single(query => query.Where(c => c.Status == CommentStatus.Verify).Count());
+ }
+
+
+ public IList Find(Func, IQueryable> expr)
+ {
+ return _commentRepository.Find(expr);
+ }
+
+ public object Single(Func, object> expr)
+ {
+ return _commentRepository.Single(expr);
+ }
+
+
+ public void DeleteComment(int commentId)
+ {
+ Comment comment = GetComment(commentId);
+ Article article = _articleService.GetArticle(comment.Article.ArticleId);
+ article.CommentCount--;
+ _articleService.UpdateArticle(article);
+ _commentRepository.Delete(comment.CommentId);
+ }
+
+
+ public void UpdateComment(Comment comment)
+ {
+ _commentRepository.Update(comment);
+ }
+ }
+
+}
diff --git a/MyBlog/Blog.Domain/SettingService.cs b/MyBlog/Blog.Domain/SettingService.cs
index eede751..54f391b 100644
--- a/MyBlog/Blog.Domain/SettingService.cs
+++ b/MyBlog/Blog.Domain/SettingService.cs
@@ -33,7 +33,7 @@ public IDictionary GetAllSetting()
IList list = _settingRepository.GetAll();
foreach (var setting in list)
{
- if (!string.IsNullOrEmpty(setting.SettingKey))
+ if (setting != null && !string.IsNullOrEmpty(setting.SettingKey))
_settings[setting.SettingKey] = setting.SettingValue;
}
}
@@ -68,6 +68,7 @@ public void SetSetting(string key, string value)
foreach (var setting in settings)
{
setting.SettingValue = value;
+ _settingRepository.Update(setting);
}
_settings[key] = value;
}
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll
index 5ee5e99..918bafe 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll and b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll.mdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll.mdb
new file mode 100644
index 0000000..81faced
Binary files /dev/null and b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.dll.mdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.pdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.pdb
index 3476c75..2c79e6a 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.pdb and b/MyBlog/Blog.Domain/bin/Debug/Blog.Domain.pdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll
index 3524218..112f52a 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll and b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll.mdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll.mdb
new file mode 100644
index 0000000..303719f
Binary files /dev/null and b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.dll.mdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Model.pdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.pdb
index 915d6a4..04511a7 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Model.pdb and b/MyBlog/Blog.Domain/bin/Debug/Blog.Model.pdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll
index 2ee7126..ae4d326 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll and b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll.mdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll.mdb
new file mode 100644
index 0000000..67c2cec
Binary files /dev/null and b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.dll.mdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.pdb b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.pdb
index be21a47..0d61408 100644
Binary files a/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.pdb and b/MyBlog/Blog.Domain/bin/Debug/Blog.Repository.pdb differ
diff --git a/MyBlog/Blog.Domain/bin/Debug/NHibernate.Linq.dll b/MyBlog/Blog.Domain/bin/Debug/NHibernate.Linq.dll
new file mode 100644
index 0000000..99bb60b
Binary files /dev/null and b/MyBlog/Blog.Domain/bin/Debug/NHibernate.Linq.dll differ
diff --git a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csproj.FileListAbsolute.txt b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csproj.FileListAbsolute.txt
index 37dcb09..8f7e914 100644
--- a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csproj.FileListAbsolute.txt
+++ b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csproj.FileListAbsolute.txt
@@ -24,3 +24,16 @@ C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Domain\bin\Debug\Iesi.Collection
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.csprojResolveAssemblyReference.cache
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.dll
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Domain.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Domain.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Model.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Repository.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\NHibernate.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Iesi.Collections.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Model.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Blog.Repository.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\NHibernate.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\bin\Debug\Iesi.Collections.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.csprojResolveAssemblyReference.cache
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Domain\obj\Debug\Blog.Domain.pdb
diff --git a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csprojResolveAssemblyReference.cache b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csprojResolveAssemblyReference.cache
index 4e2c38e..f892602 100644
Binary files a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csprojResolveAssemblyReference.cache and b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.csprojResolveAssemblyReference.cache differ
diff --git a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.dll b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.dll
index 5ee5e99..918bafe 100644
Binary files a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.dll and b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.dll differ
diff --git a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.pdb b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.pdb
index 3476c75..2c79e6a 100644
Binary files a/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.pdb and b/MyBlog/Blog.Domain/obj/Debug/Blog.Domain.pdb differ
diff --git a/MyBlog/Blog.Domain/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/MyBlog/Blog.Domain/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index c1720ee..873c99f 100644
Binary files a/MyBlog/Blog.Domain/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/MyBlog/Blog.Domain/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/MyBlog/Blog.Model/Blog.Model.csproj b/MyBlog/Blog.Model/Blog.Model.csproj
index 1990b00..bb27643 100644
--- a/MyBlog/Blog.Model/Blog.Model.csproj
+++ b/MyBlog/Blog.Model/Blog.Model.csproj
@@ -12,6 +12,8 @@
v4.0
512
+ 12.0.0
+ 2.0
true
diff --git a/MyBlog/Blog.Model/XmlMapping.hbm.xml b/MyBlog/Blog.Model/XmlMapping.hbm.xml
index 54991de..9bed456 100644
--- a/MyBlog/Blog.Model/XmlMapping.hbm.xml
+++ b/MyBlog/Blog.Model/XmlMapping.hbm.xml
@@ -100,8 +100,8 @@
-
-
+
+
@@ -143,10 +143,10 @@
-
true
@@ -75,7 +77,7 @@
- {2ec57ecb-8b69-42fc-b11b-5ef3223d182e}
+ {2EC57ECB-8B69-42FC-B11B-5EF3223D182E}
Blog.Model
diff --git a/MyBlog/Blog.Repository/CategoryRepository.cs b/MyBlog/Blog.Repository/CategoryRepository.cs
index 8935db4..f832c9e 100644
--- a/MyBlog/Blog.Repository/CategoryRepository.cs
+++ b/MyBlog/Blog.Repository/CategoryRepository.cs
@@ -15,7 +15,7 @@ public CategoryRepository(ISession session)
public System.Collections.Generic.IList GetMonthCategory()
{
//string sql = "select SUBSTRING( CONVERT(varchar,CreateDate,112),0,7) from Article Group by SUBSTRING( CONVERT(varchar,CreateDate,112),0,7)";
- string sql = "SELECT LEFT( CreateDate, 7 ) AS lefttime FROM article GROUP BY lefttime";
+ string sql = "SELECT LEFT( CreateDate, 7 ) AS lefttime FROM Article GROUP BY lefttime";
var query = session.CreateSQLQuery(sql);
var list = query.List();
diff --git a/MyBlog/Blog.Repository/RepositoryBase.cs b/MyBlog/Blog.Repository/RepositoryBase.cs
index 4181814..49001c6 100644
--- a/MyBlog/Blog.Repository/RepositoryBase.cs
+++ b/MyBlog/Blog.Repository/RepositoryBase.cs
@@ -39,6 +39,7 @@ public void Delete(int id)
public void Update(T entity)
{
session.Merge(entity);
+ session.Flush ();
}
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll
index 3524218..112f52a 100644
Binary files a/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll and b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll differ
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll.mdb b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll.mdb
new file mode 100644
index 0000000..303719f
Binary files /dev/null and b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.dll.mdb differ
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Model.pdb b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.pdb
index 915d6a4..04511a7 100644
Binary files a/MyBlog/Blog.Repository/bin/Debug/Blog.Model.pdb and b/MyBlog/Blog.Repository/bin/Debug/Blog.Model.pdb differ
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll
index 2ee7126..ae4d326 100644
Binary files a/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll and b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll differ
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll.mdb b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll.mdb
new file mode 100644
index 0000000..67c2cec
Binary files /dev/null and b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.dll.mdb differ
diff --git a/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.pdb b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.pdb
index be21a47..0d61408 100644
Binary files a/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.pdb and b/MyBlog/Blog.Repository/bin/Debug/Blog.Repository.pdb differ
diff --git a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csproj.FileListAbsolute.txt b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csproj.FileListAbsolute.txt
index ac84d77..e093e49 100644
--- a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csproj.FileListAbsolute.txt
+++ b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csproj.FileListAbsolute.txt
@@ -24,3 +24,16 @@ C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Repository\bin\Debug\NHibernate.
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.csprojResolveAssemblyReference.cache
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.dll
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Blog.Repository.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Blog.Repository.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Blog.Model.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Iesi.Collections.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\NHibernate.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\NHibernate.Linq.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Blog.Model.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\Iesi.Collections.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\NHibernate.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\bin\Debug\NHibernate.Linq.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.csprojResolveAssemblyReference.cache
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.Repository\obj\Debug\Blog.Repository.pdb
diff --git a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csprojResolveAssemblyReference.cache b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csprojResolveAssemblyReference.cache
index ef73c11..d2ff001 100644
Binary files a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csprojResolveAssemblyReference.cache and b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.csprojResolveAssemblyReference.cache differ
diff --git a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.dll b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.dll
index 2ee7126..ae4d326 100644
Binary files a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.dll and b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.dll differ
diff --git a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.pdb b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.pdb
index be21a47..0d61408 100644
Binary files a/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.pdb and b/MyBlog/Blog.Repository/obj/Debug/Blog.Repository.pdb differ
diff --git a/MyBlog/Blog.Repository/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/MyBlog/Blog.Repository/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index 6397f35..3ccb65f 100644
Binary files a/MyBlog/Blog.Repository/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/MyBlog/Blog.Repository/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/MyBlog/Blog.WebUI/Areas/Admin/Controllers/CommentController.cs b/MyBlog/Blog.WebUI/Areas/Admin/Controllers/CommentController.cs
index 1c6f2dc..eae7078 100644
--- a/MyBlog/Blog.WebUI/Areas/Admin/Controllers/CommentController.cs
+++ b/MyBlog/Blog.WebUI/Areas/Admin/Controllers/CommentController.cs
@@ -1,295 +1,294 @@
-using Blog.Domain;
-using Blog.Domain.Interface;
-using Blog.Model;
-using Blog.WebUI.Areas.Admin.Models;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
-
-namespace Blog.WebUI.Areas.Admin.Controllers
-{
- public class CommentController : Controller
- {
- private ICommentService _commentService;
- private ISettingService _settingService;
- private IArticleService _articleService;
-
- public CommentController(IArticleService articleService, ICommentService commentService, ISettingService settingService)
- {
- _commentService = commentService;
- _settingService = settingService;
- _articleService = articleService;
- }
- [AdminAuthorize]
- public ActionResult Index(CommentSearchModel model, string message = null, string method = null, int[] commentIds = null)
- {
- if (method != null)
- {
- if (method.Equals("Trash"))
- return TrashList(commentIds);
- else if (method.Equals("Delete"))
- return DeleteList(commentIds);
- else if (method.Equals("UnTrash"))
- return UnTrashList(commentIds);
- }
-
- ViewBag.Message = message;
- int pageSize = int.Parse(_settingService.GetSetting("AdminCommentPageSize"));
- if (model.PageSize != null && model.PageSize > 0 && model.PageSize != pageSize)
- {
- _settingService.SetSetting("AdminCommentPageSize", model.PageSize.ToString());
- }
- else
- {
- model.PageSize = pageSize;
- }
- PageInfo pageInfo = new PageInfo();
- int count = (int)_commentService.Single(query => BulidCommentQuery(query, model).Count());
-
- pageInfo.TotalItem = count;
- pageInfo.PageSize = model.PageSize.Value;
-
- model.PageIndex = model.PageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : model.PageIndex;
-
- IList list = _commentService.Find(query => BulidCommentQuery(query, model).OrderByDescending(c => c.CreateDate).Skip((model.PageIndex - 1) * model.PageSize.Value).Take(model.PageSize.Value));
- pageInfo.PageItems = list;
- model.PageInfo = pageInfo;
-
- model.AllCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open) || (c.Status == CommentStatus.Verify)).Count());
- model.OpenCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open)).Count());
- model.VerifyCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Verify)).Count());
- model.DeleteCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Delete)).Count());
-
-
- IDictionary VerifyComment = new Dictionary();
- foreach (Comment comment in model.PageInfo)
- {
- if (!VerifyComment.ContainsKey(comment.Article.ArticleId))
- VerifyComment[comment.Article.ArticleId] = (int)_commentService.GetCommentSingle(query => query.Where(c => c.Article.Type == ArticleType.Blog && c.Article.ArticleId == comment.Article.ArticleId && c.Status == CommentStatus.Verify).Count());
- }
- ViewBag.VerifyComment = VerifyComment;
- return View(model);
- }
-
- public ActionResult Delete(int id)
- {
- string Message = "1 个项目成功删除。";
- try
- {
- _commentService.DeleteComment(id);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public ActionResult Trash(int id)
- {
- string Message = "1 个项目成功移至回收站。";
- try
- {
- Comment comment = _commentService.GetComment(id);
- comment.Status = CommentStatus.Delete;
- _commentService.UpdateComment(comment);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public ActionResult DeleteList(int[] commentIds)
- {
- string Message = commentIds.Length + " 个项目成功删除。";
- try
- {
- foreach (int id in commentIds)
- _commentService.DeleteComment(id);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public ActionResult TrashList(int[] commentIds)
- {
- string Message = commentIds.Length + " 个项目成功移至回收站。";
- try
- {
- foreach (int id in commentIds)
- {
- Comment comment = _commentService.GetComment(id);
- comment.Status = CommentStatus.Delete;
- _commentService.UpdateComment(comment);
- }
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public ActionResult UnTrash(int id)
- {
-
- string Message = "1 个项目成功从回收站还原。";
- try
- {
- Comment comment = _commentService.GetComment(id);
- comment.Status = CommentStatus.Open;
- _commentService.UpdateComment(comment);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public ActionResult UnTrashList(int[] commentIds)
- {
-
- string Message = commentIds.Length + " 个项目成功从回收站还原。";
- try
- {
- foreach (int id in commentIds)
- {
- Comment comment = _commentService.GetComment(id);
- comment.Status = CommentStatus.Open;
- _commentService.UpdateComment(comment);
- }
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
- [AdminAuthorize]
- [HttpGet]
- public ActionResult Edit(int id)
- {
- string Message = "";
- try
- {
- Comment comment = _commentService.GetComment(id);
-
- return View(comment);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- return RedirectToAction("Index", new { Message = Message });
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- return RedirectToAction("Index", new { Message = Message });
- }
- }
-
- [AdminAuthorize]
- [HttpPost]
- public ActionResult Edit(Comment comment)
- {
- string Message = "";
- try
- {
- Comment comment2 = _commentService.GetComment(comment.CommentId);
- comment2.Content = comment.Content;
- comment2.Author = comment.Author;
- comment2.AuthorMail = comment.AuthorMail;
- comment2.Status = comment.Status;
- _commentService.UpdateComment(comment2);
- return RedirectToAction("Index", new { Message = "评论编辑成功。" });
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- return RedirectToAction("Index", new { Message = Message });
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- return RedirectToAction("Index", new { Message = Message });
- }
- }
-
- public ActionResult Open(int id)
- {
- string Message = "1 个项目成功批准。";
- try
- {
- Comment comment = _commentService.GetComment(id);
- comment.Status = CommentStatus.Open;
- _commentService.UpdateComment(comment);
- }
- catch (DomainException ex)
- {
- Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- Message = ex.Message;
- }
- return RedirectToAction("Index", new { Message = Message });
- }
-
- public IQueryable BulidCommentQuery(IQueryable query, CommentSearchModel model)
- {
- if (!string.IsNullOrEmpty(model.Search))
- {
- query = query.Where(c => c.Author.Contains(model.Search) || c.Content.Contains(model.Search));
- }
-
- if (!string.IsNullOrEmpty(model.IpAddress))
- {
- query = query.Where(c => c.AuthorIP == model.IpAddress);
- }
-
- if (model.Status == null)
- {
- query = query.Where(c => c.Status == CommentStatus.Open || c.Status == CommentStatus.Verify);
- }
- else
- {
- query = query.Where(c => c.Status == model.Status);
- }
-
- return query;
- }
-
- }
-}
+using Blog.Domain;
+using Blog.Domain.Interface;
+using Blog.Model;
+using Blog.WebUI.Areas.Admin.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+
+namespace Blog.WebUI.Areas.Admin.Controllers
+{
+ public class CommentController : Controller
+ {
+ private ICommentService _commentService;
+ private ISettingService _settingService;
+
+ public CommentController(IArticleService articleService, ICommentService commentService, ISettingService settingService)
+ {
+ _commentService = commentService;
+ _settingService = settingService;
+ }
+ [AdminAuthorize]
+ public ActionResult Index(CommentSearchModel model, string message = null, string method = null, int[] commentIds = null)
+ {
+ if (method != null)
+ {
+ if (method.Equals("Trash"))
+ return TrashList(commentIds);
+ else if (method.Equals("Delete"))
+ return DeleteList(commentIds);
+ else if (method.Equals("UnTrash"))
+ return UnTrashList(commentIds);
+ }
+
+ ViewBag.Message = message;
+ int pageSize = int.Parse(_settingService.GetSetting("AdminCommentPageSize"));
+ if (model.PageSize != null && model.PageSize > 0 && model.PageSize != pageSize)
+ {
+ _settingService.SetSetting("AdminCommentPageSize", model.PageSize.ToString());
+ }
+ else
+ {
+ model.PageSize = pageSize;
+ }
+ PageInfo pageInfo = new PageInfo();
+ int count = (int)_commentService.Single(query => BulidCommentQuery(query, model).Count());
+
+ pageInfo.TotalItem = count;
+ pageInfo.PageSize = model.PageSize.Value;
+
+ model.PageIndex = model.PageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : model.PageIndex;
+ model.PageIndex = model.PageIndex <= 0 ? 1 : model.PageIndex;
+
+ IList list = _commentService.Find(query => BulidCommentQuery(query, model).OrderByDescending(c => c.CreateDate).Skip((model.PageIndex - 1) * model.PageSize.Value).Take(model.PageSize.Value));
+ pageInfo.PageItems = list;
+ model.PageInfo = pageInfo;
+
+ model.AllCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open) || (c.Status == CommentStatus.Verify)).Count());
+ model.OpenCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Open)).Count());
+ model.VerifyCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Verify)).Count());
+ model.DeleteCount = (int)_commentService.Single(query => query.Where(c => (c.Status == CommentStatus.Delete)).Count());
+
+
+ IDictionary VerifyComment = new Dictionary();
+ foreach (Comment comment in model.PageInfo)
+ {
+ if (!VerifyComment.ContainsKey(comment.Article.ArticleId))
+ VerifyComment[comment.Article.ArticleId] = (int)_commentService.GetCommentSingle(query => query.Where(c => c.Article.Type == ArticleType.Blog && c.Article.ArticleId == comment.Article.ArticleId && c.Status == CommentStatus.Verify).Count());
+ }
+ ViewBag.VerifyComment = VerifyComment;
+ return View(model);
+ }
+
+ public ActionResult Delete(int id)
+ {
+ string Message = "1 个项目成功删除。";
+ try
+ {
+ _commentService.DeleteComment(id);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public ActionResult Trash(int id)
+ {
+ string Message = "1 个项目成功移至回收站。";
+ try
+ {
+ Comment comment = _commentService.GetComment(id);
+ comment.Status = CommentStatus.Delete;
+ _commentService.UpdateComment(comment);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public ActionResult DeleteList(int[] commentIds)
+ {
+ string Message = commentIds.Length + " 个项目成功删除。";
+ try
+ {
+ foreach (int id in commentIds)
+ _commentService.DeleteComment(id);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public ActionResult TrashList(int[] commentIds)
+ {
+ string Message = commentIds.Length + " 个项目成功移至回收站。";
+ try
+ {
+ foreach (int id in commentIds)
+ {
+ Comment comment = _commentService.GetComment(id);
+ comment.Status = CommentStatus.Delete;
+ _commentService.UpdateComment(comment);
+ }
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public ActionResult UnTrash(int id)
+ {
+
+ string Message = "1 个项目成功从回收站还原。";
+ try
+ {
+ Comment comment = _commentService.GetComment(id);
+ comment.Status = CommentStatus.Open;
+ _commentService.UpdateComment(comment);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public ActionResult UnTrashList(int[] commentIds)
+ {
+
+ string Message = commentIds.Length + " 个项目成功从回收站还原。";
+ try
+ {
+ foreach (int id in commentIds)
+ {
+ Comment comment = _commentService.GetComment(id);
+ comment.Status = CommentStatus.Open;
+ _commentService.UpdateComment(comment);
+ }
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+ [AdminAuthorize]
+ [HttpGet]
+ public ActionResult Edit(int id)
+ {
+ string Message = "";
+ try
+ {
+ Comment comment = _commentService.GetComment(id);
+
+ return View(comment);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ return RedirectToAction("Index", new { Message = Message });
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ return RedirectToAction("Index", new { Message = Message });
+ }
+ }
+
+ [AdminAuthorize]
+ [HttpPost]
+ public ActionResult Edit(Comment comment)
+ {
+ string Message = "";
+ try
+ {
+ Comment comment2 = _commentService.GetComment(comment.CommentId);
+ comment2.Content = comment.Content;
+ comment2.Author = comment.Author;
+ comment2.AuthorMail = comment.AuthorMail;
+ comment2.Status = comment.Status;
+ _commentService.UpdateComment(comment2);
+ return RedirectToAction("Index", new { Message = "评论编辑成功。" });
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ return RedirectToAction("Index", new { Message = Message });
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ return RedirectToAction("Index", new { Message = Message });
+ }
+ }
+
+ public ActionResult Open(int id)
+ {
+ string Message = "1 个项目成功批准。";
+ try
+ {
+ Comment comment = _commentService.GetComment(id);
+ comment.Status = CommentStatus.Open;
+ _commentService.UpdateComment(comment);
+ }
+ catch (DomainException ex)
+ {
+ Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ Message = ex.Message;
+ }
+ return RedirectToAction("Index", new { Message = Message });
+ }
+
+ public IQueryable BulidCommentQuery(IQueryable query, CommentSearchModel model)
+ {
+ if (!string.IsNullOrEmpty(model.Search))
+ {
+ query = query.Where(c => c.Author.Contains(model.Search) || c.Content.Contains(model.Search));
+ }
+
+ if (!string.IsNullOrEmpty(model.IpAddress))
+ {
+ query = query.Where(c => c.AuthorIP == model.IpAddress);
+ }
+
+ if (model.Status == null)
+ {
+ query = query.Where(c => c.Status == CommentStatus.Open || c.Status == CommentStatus.Verify);
+ }
+ else
+ {
+ query = query.Where(c => c.Status == model.Status);
+ }
+
+ return query;
+ }
+
+ }
+}
diff --git a/MyBlog/Blog.WebUI/Areas/Admin/Controllers/UserController.cs b/MyBlog/Blog.WebUI/Areas/Admin/Controllers/UserController.cs
index 4b84642..084b2f2 100644
--- a/MyBlog/Blog.WebUI/Areas/Admin/Controllers/UserController.cs
+++ b/MyBlog/Blog.WebUI/Areas/Admin/Controllers/UserController.cs
@@ -1,357 +1,357 @@
-using Blog.Domain;
-using Blog.Domain.Interface;
-using Blog.Model;
-using Blog.WebUI.Areas.Admin.Models;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
-
-namespace Blog.WebUI.Areas.Admin.Controllers
-{
- public class UserController : Controller
- {
- private IUserService _userService;
- private ISettingService _settingService;
-
- public UserController(ISettingService settingService, IUserService userService)
- {
- _userService = userService;
- _settingService = settingService;
- }
-
- [AdminAuthorize]
- public ActionResult Index(UserSearchModel model, string message = null, string method = null, int[] userIds = null)
- {
- ///操作判断开始
- if (!string.IsNullOrEmpty(method))
- {
- if (method.Equals("Delete"))
- {
- return DeleteList(userIds);
- }
- }
- ViewBag.Message = message;
- ///取得每页显示数
- int pageSize = int.Parse(_settingService.GetSetting("AdminUserPageSize"));
- if (model.PageSize != null && model.PageSize > 0 && model.PageSize != pageSize)
- {
- _settingService.SetSetting("AdminUserPageSize", model.PageSize.ToString());
- }
- else
- {
- model.PageSize = pageSize;
- }
- PageInfo pageInfo = new PageInfo();
- int count = (int)_userService.Single(query => BulidQuery(query, model).Count());
-
-
- model.AllCount = (int)_userService.Single(query => query.Count());
- model.AdminCount = (int)_userService.Single(query => query.Where(u => u.Role == UserRole.Admin).Count());
- model.ReaderCount = (int)_userService.Single(query => query.Where(u => u.Role == UserRole.Reader).Count());
-
- pageInfo.TotalItem = count;
- pageInfo.PageSize = model.PageSize.Value;
-
- model.PageIndex = model.PageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : model.PageIndex;
-
- IList list = _userService.Find(query => BulidQuery(query, model).OrderByDescending(c => c.RegisterDate).Skip((model.PageIndex - 1) * model.PageSize.Value).Take(model.PageSize.Value));
- pageInfo.PageItems = list;
- model.PageInfo = pageInfo;
- return View(model);
- }
-
-
- public IQueryable BulidQuery(IQueryable query, UserSearchModel model)
- {
- if (model.Role != null)
- query = query.Where(u => u.Role == model.Role);
- if (!string.IsNullOrEmpty(model.Search))
- query = query.Where(u => u.UserName.Contains(model.Search) || u.NiceName.Contains(model.Search));
- return query;
- }
-
- public ActionResult Delete(int id)
- {
- string message = "1 个用户成功删除。";
- try
- {
- _userService.Delete(id);
- }
- catch (Exception ex)
- {
- message = ex.Message;
- }
- return RedirectToAction("Index", new { message = message });
- }
-
- public ActionResult DeleteList(int[] userIds)
- {
- string message = userIds.Length + " 个用户成功删除。";
- try
- {
- foreach (int id in userIds)
- _userService.Delete(id);
- }
- catch (Exception ex)
- {
- message = ex.Message;
- }
- return RedirectToAction("Index", new { message = message });
- }
-
- [UserAuthorize]
- [HttpGet]
- public ActionResult Info()
- {
- return View(_userService.GetLoginUser());
- }
-
- [UserAuthorize]
- [HttpPost]
- public ActionResult Info(UserInfoModel model)
- {
- User user = _userService.GetLoginUser();
- if (ModelState.IsValid)
- {
- try
- {
- if (!string.IsNullOrEmpty(model.Password))
- {
- user.Password = model.Password;
- }
- user.NiceName = model.NiceName;
-
-
- if (Request.Files.Count > 0 && !string.IsNullOrEmpty(model.Picture))
- {
- string extension = Path.GetExtension(Request.Files[0].FileName).ToLower();
-
- if (extension == ".jpg" || extension == ".png" || extension == ".bmp")
- {
-
- if (user.Extends.ContainsKey("Picture"))
- {
- if (System.IO.File.Exists(Server.MapPath("~/") + user.Extends["Picture"]))
- {
- System.IO.File.Delete(Server.MapPath("~/") + user.Extends["Picture"]);
- }
- }
- string path = "/Content/Upload/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
- string savePath = Server.MapPath("~/") + path;
-
- if (!Directory.Exists(savePath))
- {
- Directory.CreateDirectory(savePath);
- }
- Random r = new Random();
- int length = r.Next(10);
- string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + GetRandomString(length) + extension;
- Request.Files[0].SaveAs(savePath + fileName);
- user.Extends["Picture"] = path + fileName;
- }
- else
- {
- throw new Exception("对不起,不支持该格式的头像。目前只支持 .jpg、.png、.bmp格式的头像");
- }
- }
- _userService.UpdateUser(user);
- }
- catch (Domain.DomainException ex)
- {
- ViewBag.Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- ViewBag.Message = ex.Message;
- }
- }
- else
- {
- foreach (var value in ModelState.Values)
- {
- foreach (var error in value.Errors)
- {
- ViewBag.Message = error.ErrorMessage;
- break;
- }
- if (ViewBag.Message != null)
- {
- break;
- }
- }
- }
-
- return View(user);
- }
-
- [AdminAuthorize]
- [HttpGet]
- public ActionResult Edit(int id)
- {
- try
- {
- User user = _userService.GetUserById(id);
-
- return View("Info", user);
- }
- catch (Exception ex)
- {
- return RedirectToAction("Index", new { message = ex.Message });
- }
- }
-
- [AdminAuthorize]
- [HttpPost]
- public ActionResult Edit(UserInfoModel model, int id)
- {
- User user = null;
- try
- {
- user = _userService.GetUserById(id);
- if (ModelState.IsValid)
- {
- try
- {
- if (!string.IsNullOrEmpty(model.Password))
- {
- user.Password = model.Password;
- }
- user.NiceName = model.NiceName;
-
-
- if (Request.Files.Count > 0 && !string.IsNullOrEmpty(model.Picture))
- {
- string extension = Path.GetExtension(Request.Files[0].FileName).ToLower();
-
- if (extension == ".jpg" || extension == ".png" || extension == ".bmp")
- {
-
- if (user.Extends.ContainsKey("Picture"))
- {
- if (System.IO.File.Exists(Server.MapPath("~/") + user.Extends["Picture"]))
- {
- System.IO.File.Delete(Server.MapPath("~/") + user.Extends["Picture"]);
- }
- }
- string path = "/Content/Upload/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
- string savePath = Server.MapPath("~/") + path;
-
- if (!Directory.Exists(savePath))
- {
- Directory.CreateDirectory(savePath);
- }
- Random r = new Random();
- int length = r.Next(10);
- string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + GetRandomString(length) + extension;
- Request.Files[0].SaveAs(savePath + fileName);
- user.Extends["Picture"] = path + fileName;
- }
- else
- {
- throw new Exception("对不起,不支持该格式的头像。目前只支持 .jpg、.png、.bmp格式的头像");
- }
- }
- _userService.UpdateUser(user);
- return RedirectToAction("Index", new { message = "编辑成功。" });
- }
- catch (Domain.DomainException ex)
- {
- ViewBag.Message = ex.Errors.First().Value;
- }
- catch (Exception ex)
- {
- ViewBag.Message = ex.Message;
- }
- }
- else
- {
- foreach (var value in ModelState.Values)
- {
- foreach (var error in value.Errors)
- {
- ViewBag.Message = error.ErrorMessage;
- break;
- }
- if (ViewBag.Message != null)
- {
- break;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ViewBag.Message = ex.Message;
- }
- if (user != null)
- {
- return View("Info", user);
- }
- else
- {
- return RedirectToAction("Index", new { message = ViewBag.Message });
- }
- }
-
- [AdminAuthorize]
- [HttpGet]
- public ActionResult Add()
- {
- return View();
- }
-
- [AdminAuthorize]
- [HttpPost]
- public ActionResult Add(UserAddModel model)
- {
- if (ModelState.IsValid)
- {
- try
- {
- User user = new User() { UserName = model.UserName, Email = model.Email, Role = model.Role, RegisterDate = DateTime.Now, NiceName = model.UserName };
- _userService.AddUser(user);
- return RedirectToAction("Index", new { Message = "用户添加成功。" });
- }
- catch (Exception ex)
- {
- ViewBag.Message = ex.Message;
- }
- }
- else
- {
-
- foreach (var value in ModelState.Values)
- {
- foreach (var error in value.Errors)
- {
- ViewBag.Message = error.ErrorMessage;
- break;
- }
- if (ViewBag.Message != null)
- {
- break;
- }
- }
- }
- return View();
- }
-
-
- private string GetRandomString(int length)
- {
- string str = string.Empty;
- Random random = new Random();
- for (int i = 0; i < length; i++)
- {
- str += (char)random.Next(65, 112);
- }
- str = str.Replace(@"\", "_");
- str = str.Replace("/", "_");
- return str;
- }
- }
-
-}
+using Blog.Domain;
+using Blog.Domain.Interface;
+using Blog.Model;
+using Blog.WebUI.Areas.Admin.Models;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+
+namespace Blog.WebUI.Areas.Admin.Controllers
+{
+ public class UserController : Controller
+ {
+ private IUserService _userService;
+ private ISettingService _settingService;
+
+ public UserController(ISettingService settingService, IUserService userService)
+ {
+ _userService = userService;
+ _settingService = settingService;
+ }
+
+ [AdminAuthorize]
+ public ActionResult Index(UserSearchModel model, string message = null, string method = null, int[] userIds = null)
+ {
+ ///操作判断开始
+ if (!string.IsNullOrEmpty(method))
+ {
+ if (method.Equals("Delete"))
+ {
+ return DeleteList(userIds);
+ }
+ }
+ ViewBag.Message = message;
+ ///取得每页显示数
+ int pageSize = int.Parse(_settingService.GetSetting("AdminUserPageSize"));
+ if (model.PageSize != null && model.PageSize > 0 && model.PageSize != pageSize)
+ {
+ _settingService.SetSetting("AdminUserPageSize", model.PageSize.ToString());
+ }
+ else
+ {
+ model.PageSize = pageSize;
+ }
+ PageInfo pageInfo = new PageInfo();
+ int count = (int)_userService.Single(query => BulidQuery(query, model).Count());
+
+
+ model.AllCount = (int)_userService.Single(query => query.Count());
+ model.AdminCount = (int)_userService.Single(query => query.Where(u => u.Role == UserRole.Admin).Count());
+ model.ReaderCount = (int)_userService.Single(query => query.Where(u => u.Role == UserRole.Reader).Count());
+
+ pageInfo.TotalItem = count;
+ pageInfo.PageSize = model.PageSize.Value;
+
+ model.PageIndex = model.PageIndex > pageInfo.TotalPage ? pageInfo.TotalPage : model.PageIndex;
+ model.PageIndex = model.PageIndex <= 0 ? 1 : model.PageIndex ;
+ IList list = _userService.Find(query => BulidQuery(query, model).OrderByDescending(c => c.RegisterDate).Skip((model.PageIndex - 1) * model.PageSize.Value).Take(model.PageSize.Value));
+ pageInfo.PageItems = list;
+ model.PageInfo = pageInfo;
+ return View(model);
+ }
+
+
+ public IQueryable BulidQuery(IQueryable query, UserSearchModel model)
+ {
+ if (model.Role != null)
+ query = query.Where(u => u.Role == model.Role);
+ if (!string.IsNullOrEmpty(model.Search))
+ query = query.Where(u => u.UserName.Contains(model.Search) || u.NiceName.Contains(model.Search));
+ return query;
+ }
+
+ public ActionResult Delete(int id)
+ {
+ string message = "1 个用户成功删除。";
+ try
+ {
+ _userService.Delete(id);
+ }
+ catch (Exception ex)
+ {
+ message = ex.Message;
+ }
+ return RedirectToAction("Index", new { message = message });
+ }
+
+ public ActionResult DeleteList(int[] userIds)
+ {
+ string message = userIds.Length + " 个用户成功删除。";
+ try
+ {
+ foreach (int id in userIds)
+ _userService.Delete(id);
+ }
+ catch (Exception ex)
+ {
+ message = ex.Message;
+ }
+ return RedirectToAction("Index", new { message = message });
+ }
+
+ [UserAuthorize]
+ [HttpGet]
+ public ActionResult Info()
+ {
+ return View(_userService.GetLoginUser());
+ }
+
+ [UserAuthorize]
+ [HttpPost]
+ public ActionResult Info(UserInfoModel model)
+ {
+ User user = _userService.GetLoginUser();
+ if (ModelState.IsValid)
+ {
+ try
+ {
+ if (!string.IsNullOrEmpty(model.Password))
+ {
+ user.Password = model.Password;
+ }
+ user.NiceName = model.NiceName;
+
+
+ if (Request.Files.Count > 0 && !string.IsNullOrEmpty(model.Picture))
+ {
+ string extension = Path.GetExtension(Request.Files[0].FileName).ToLower();
+
+ if (extension == ".jpg" || extension == ".png" || extension == ".bmp")
+ {
+
+ if (user.Extends.ContainsKey("Picture"))
+ {
+ if (System.IO.File.Exists(Server.MapPath("~/") + user.Extends["Picture"]))
+ {
+ System.IO.File.Delete(Server.MapPath("~/") + user.Extends["Picture"]);
+ }
+ }
+ string path = "/Content/Upload/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
+ string savePath = Server.MapPath("~/") + path;
+
+ if (!Directory.Exists(savePath))
+ {
+ Directory.CreateDirectory(savePath);
+ }
+ Random r = new Random();
+ int length = r.Next(10);
+ string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + GetRandomString(length) + extension;
+ Request.Files[0].SaveAs(savePath + fileName);
+ user.Extends["Picture"] = path + fileName;
+ }
+ else
+ {
+ throw new Exception("对不起,不支持该格式的头像。目前只支持 .jpg、.png、.bmp格式的头像");
+ }
+ }
+ _userService.UpdateUser(user);
+ }
+ catch (Domain.DomainException ex)
+ {
+ ViewBag.Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ ViewBag.Message = ex.Message;
+ }
+ }
+ else
+ {
+ foreach (var value in ModelState.Values)
+ {
+ foreach (var error in value.Errors)
+ {
+ ViewBag.Message = error.ErrorMessage;
+ break;
+ }
+ if (ViewBag.Message != null)
+ {
+ break;
+ }
+ }
+ }
+
+ return View(user);
+ }
+
+ [AdminAuthorize]
+ [HttpGet]
+ public ActionResult Edit(int id)
+ {
+ try
+ {
+ User user = _userService.GetUserById(id);
+
+ return View("Info", user);
+ }
+ catch (Exception ex)
+ {
+ return RedirectToAction("Index", new { message = ex.Message });
+ }
+ }
+
+ [AdminAuthorize]
+ [HttpPost]
+ public ActionResult Edit(UserInfoModel model, int id)
+ {
+ User user = null;
+ try
+ {
+ user = _userService.GetUserById(id);
+ if (ModelState.IsValid)
+ {
+ try
+ {
+ if (!string.IsNullOrEmpty(model.Password))
+ {
+ user.Password = model.Password;
+ }
+ user.NiceName = model.NiceName;
+
+
+ if (Request.Files.Count > 0 && !string.IsNullOrEmpty(model.Picture))
+ {
+ string extension = Path.GetExtension(Request.Files[0].FileName).ToLower();
+
+ if (extension == ".jpg" || extension == ".png" || extension == ".bmp")
+ {
+
+ if (user.Extends.ContainsKey("Picture"))
+ {
+ if (System.IO.File.Exists(Server.MapPath("~/") + user.Extends["Picture"]))
+ {
+ System.IO.File.Delete(Server.MapPath("~/") + user.Extends["Picture"]);
+ }
+ }
+ string path = "/Content/Upload/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
+ string savePath = Server.MapPath("~/") + path;
+
+ if (!Directory.Exists(savePath))
+ {
+ Directory.CreateDirectory(savePath);
+ }
+ Random r = new Random();
+ int length = r.Next(10);
+ string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + GetRandomString(length) + extension;
+ Request.Files[0].SaveAs(savePath + fileName);
+ user.Extends["Picture"] = path + fileName;
+ }
+ else
+ {
+ throw new Exception("对不起,不支持该格式的头像。目前只支持 .jpg、.png、.bmp格式的头像");
+ }
+ }
+ _userService.UpdateUser(user);
+ return RedirectToAction("Index", new { message = "编辑成功。" });
+ }
+ catch (Domain.DomainException ex)
+ {
+ ViewBag.Message = ex.Errors.First().Value;
+ }
+ catch (Exception ex)
+ {
+ ViewBag.Message = ex.Message;
+ }
+ }
+ else
+ {
+ foreach (var value in ModelState.Values)
+ {
+ foreach (var error in value.Errors)
+ {
+ ViewBag.Message = error.ErrorMessage;
+ break;
+ }
+ if (ViewBag.Message != null)
+ {
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ViewBag.Message = ex.Message;
+ }
+ if (user != null)
+ {
+ return View("Info", user);
+ }
+ else
+ {
+ return RedirectToAction("Index", new { message = ViewBag.Message });
+ }
+ }
+
+ [AdminAuthorize]
+ [HttpGet]
+ public ActionResult Add()
+ {
+ return View();
+ }
+
+ [AdminAuthorize]
+ [HttpPost]
+ public ActionResult Add(UserAddModel model)
+ {
+ if (ModelState.IsValid)
+ {
+ try
+ {
+ User user = new User() { UserName = model.UserName, Email = model.Email, Role = model.Role, RegisterDate = DateTime.Now, NiceName = model.UserName };
+ _userService.AddUser(user);
+ return RedirectToAction("Index", new { Message = "用户添加成功。" });
+ }
+ catch (Exception ex)
+ {
+ ViewBag.Message = ex.Message;
+ }
+ }
+ else
+ {
+
+ foreach (var value in ModelState.Values)
+ {
+ foreach (var error in value.Errors)
+ {
+ ViewBag.Message = error.ErrorMessage;
+ break;
+ }
+ if (ViewBag.Message != null)
+ {
+ break;
+ }
+ }
+ }
+ return View();
+ }
+
+
+ private string GetRandomString(int length)
+ {
+ string str = string.Empty;
+ Random random = new Random();
+ for (int i = 0; i < length; i++)
+ {
+ str += (char)random.Next(65, 112);
+ }
+ str = str.Replace(@"\", "_");
+ str = str.Replace("/", "_");
+ return str;
+ }
+ }
+
+}
diff --git a/MyBlog/Blog.WebUI/Blog.WebUI.csproj b/MyBlog/Blog.WebUI/Blog.WebUI.csproj
index 999e538..24f9422 100644
--- a/MyBlog/Blog.WebUI/Blog.WebUI.csproj
+++ b/MyBlog/Blog.WebUI/Blog.WebUI.csproj
@@ -55,18 +55,15 @@
..\packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll
-
..\packages\NHibernate.3.3.3.4000\lib\Net35\NHibernate.dll
-
-
@@ -77,38 +74,27 @@
-
- True
- ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
-
-
- True
- ..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.Helpers.dll
-
-
- True
- ..\packages\Microsoft.AspNet.Mvc.3.0.20105.1\lib\net40\System.Web.Mvc.dll
-
..\packages\Microsoft.AspNet.Providers.Core.1.1\lib\net40\System.Web.Providers.dll
-
- True
+
+
+ ..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.Helpers.dll
+
+
..\packages\Microsoft.AspNet.Razor.1.0.20105.408\lib\net40\System.Web.Razor.dll
-
- True
+
..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.dll
-
- True
+
..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Deployment.dll
-
- True
+
..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll
-
+
+
@@ -159,9 +145,6 @@
-
- Always
-
Always
@@ -946,15 +929,15 @@
- {1ae1a185-50ca-447c-a07e-dcc530651c0d}
+ {1AE1A185-50CA-447C-A07E-DCC530651C0D}
Blog.Domain
- {2ec57ecb-8b69-42fc-b11b-5ef3223d182e}
+ {2EC57ECB-8B69-42FC-B11B-5EF3223D182E}
Blog.Model
- {7a88f526-8e70-4385-aeb2-fea874ac0814}
+ {7A88F526-8E70-4385-AEB2-FEA874AC0814}
Blog.Repository
@@ -985,6 +968,16 @@
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
\ No newline at end of file
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Domain.dll b/MyBlog/Blog.WebUI/bin/Blog.Domain.dll
index 5ee5e99..918bafe 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Domain.dll and b/MyBlog/Blog.WebUI/bin/Blog.Domain.dll differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Domain.dll.mdb b/MyBlog/Blog.WebUI/bin/Blog.Domain.dll.mdb
new file mode 100644
index 0000000..81faced
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/Blog.Domain.dll.mdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Domain.pdb b/MyBlog/Blog.WebUI/bin/Blog.Domain.pdb
index 3476c75..2c79e6a 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Domain.pdb and b/MyBlog/Blog.WebUI/bin/Blog.Domain.pdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Model.dll b/MyBlog/Blog.WebUI/bin/Blog.Model.dll
index 3524218..112f52a 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Model.dll and b/MyBlog/Blog.WebUI/bin/Blog.Model.dll differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Model.dll.mdb b/MyBlog/Blog.WebUI/bin/Blog.Model.dll.mdb
new file mode 100644
index 0000000..303719f
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/Blog.Model.dll.mdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Model.pdb b/MyBlog/Blog.WebUI/bin/Blog.Model.pdb
index 915d6a4..04511a7 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Model.pdb and b/MyBlog/Blog.WebUI/bin/Blog.Model.pdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Repository.dll b/MyBlog/Blog.WebUI/bin/Blog.Repository.dll
index 2ee7126..ae4d326 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Repository.dll and b/MyBlog/Blog.WebUI/bin/Blog.Repository.dll differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Repository.dll.mdb b/MyBlog/Blog.WebUI/bin/Blog.Repository.dll.mdb
new file mode 100644
index 0000000..67c2cec
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/Blog.Repository.dll.mdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.Repository.pdb b/MyBlog/Blog.WebUI/bin/Blog.Repository.pdb
index be21a47..0d61408 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.Repository.pdb and b/MyBlog/Blog.WebUI/bin/Blog.Repository.pdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll b/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll
index 165fe5f..c359464 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll and b/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll.mdb b/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll.mdb
new file mode 100644
index 0000000..bfee9e1
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/Blog.WebUI.dll.mdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Blog.WebUI.pdb b/MyBlog/Blog.WebUI/bin/Blog.WebUI.pdb
index 742788c..e73ae2e 100644
Binary files a/MyBlog/Blog.WebUI/bin/Blog.WebUI.pdb and b/MyBlog/Blog.WebUI/bin/Blog.WebUI.pdb differ
diff --git a/MyBlog/Blog.WebUI/bin/Microsoft.Web.Infrastructure.dll b/MyBlog/Blog.WebUI/bin/Microsoft.Web.Infrastructure.dll
deleted file mode 100644
index 85f1138..0000000
Binary files a/MyBlog/Blog.WebUI/bin/Microsoft.Web.Infrastructure.dll and /dev/null differ
diff --git a/MyBlog/Blog.WebUI/bin/MySql.Data.dll b/MyBlog/Blog.WebUI/bin/MySql.Data.dll
new file mode 100644
index 0000000..da3babd
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/MySql.Data.dll differ
diff --git a/MyBlog/Blog.WebUI/bin/a.out b/MyBlog/Blog.WebUI/bin/a.out
new file mode 100644
index 0000000..9d33904
Binary files /dev/null and b/MyBlog/Blog.WebUI/bin/a.out differ
diff --git a/MyBlog/Blog.WebUI/bin/hibernate.cfg.xml b/MyBlog/Blog.WebUI/bin/hibernate.cfg.xml
index 8751139..76824d5 100644
--- a/MyBlog/Blog.WebUI/bin/hibernate.cfg.xml
+++ b/MyBlog/Blog.WebUI/bin/hibernate.cfg.xml
@@ -3,7 +3,7 @@
NHibernate.Driver.MySqlDataDriver
- Database=blog;Data Source=127.0.0.1;User Id=root;Password=
+ Database=blog;Data Source=127.0.0.1;User Id=root;Password=;Charset=utf8
NHibernate.Dialect.MySQLDialect
update
diff --git a/MyBlog/Blog.WebUI/hibernate.cfg.xml b/MyBlog/Blog.WebUI/hibernate.cfg.xml
index 8751139..76824d5 100644
--- a/MyBlog/Blog.WebUI/hibernate.cfg.xml
+++ b/MyBlog/Blog.WebUI/hibernate.cfg.xml
@@ -3,7 +3,7 @@
NHibernate.Driver.MySqlDataDriver
- Database=blog;Data Source=127.0.0.1;User Id=root;Password=
+ Database=blog;Data Source=127.0.0.1;User Id=root;Password=;Charset=utf8
NHibernate.Dialect.MySQLDialect
update
diff --git a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csproj.FileListAbsolute.txt b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csproj.FileListAbsolute.txt
index 7b50222..5c9ce29 100644
--- a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csproj.FileListAbsolute.txt
+++ b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csproj.FileListAbsolute.txt
@@ -69,3 +69,25 @@ C:\Users\Administrator\Desktop\demo\MyBlog\Blog.WebUI\bin\zh-Hans\System.Web.Pro
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.csprojResolveAssemblyReference.cache
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.dll
C:\Users\Administrator\Desktop\demo\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\hibernate.cfg.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.WebUI.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.WebUI.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Autofac.Configuration.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Autofac.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Autofac.Integration.Mvc.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Domain.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Model.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Repository.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Iesi.Collections.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\NHibernate.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\System.Web.Providers.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Domain.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Model.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Blog.Repository.pdb
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Autofac.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\Iesi.Collections.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\NHibernate.xml
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\bin\zh-Hans\System.Web.Providers.resources.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.csprojResolveAssemblyReference.cache
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.dll
+C:\Users\Administrator\Desktop\MyBlog\Blog.WebUI\obj\Debug\Blog.WebUI.pdb
diff --git a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csprojResolveAssemblyReference.cache b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csprojResolveAssemblyReference.cache
index d38f52a..afc0d82 100644
Binary files a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csprojResolveAssemblyReference.cache and b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.csprojResolveAssemblyReference.cache differ
diff --git a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.dll b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.dll
index 165fe5f..c359464 100644
Binary files a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.dll and b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.dll differ
diff --git a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.pdb b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.pdb
index 742788c..e73ae2e 100644
Binary files a/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.pdb and b/MyBlog/Blog.WebUI/obj/Debug/Blog.WebUI.pdb differ
diff --git a/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferences.cache
index 3c5c063..e16df5d 100644
Binary files a/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ
diff --git a/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index af27d17..788324e 100644
Binary files a/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/MyBlog/Blog.WebUI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/MyBlog/Blog.sln b/MyBlog/Blog.sln
index e9d4246..751d979 100644
--- a/MyBlog/Blog.sln
+++ b/MyBlog/Blog.sln
@@ -1,8 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.20617.1 PREVIEW
-MinimumVisualStudioVersion = 10.0.40219.1
+# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blog.Domain", "Blog.Domain\Blog.Domain.csproj", "{1AE1A185-50CA-447C-A07E-DCC530651C0D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blog.Model", "Blog.Model\Blog.Model.csproj", "{2EC57ECB-8B69-42FC-B11B-5EF3223D182E}"
@@ -34,6 +32,9 @@ Global
{B6101DFB-4B67-4131-9F4D-F28A2866227C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6101DFB-4B67-4131-9F4D-F28A2866227C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Blog.WebUI\Blog.WebUI.csproj
+ EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
diff --git a/MyBlog/Blog.userprefs b/MyBlog/Blog.userprefs
new file mode 100644
index 0000000..9cc3ec1
--- /dev/null
+++ b/MyBlog/Blog.userprefs
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MyBlog/Blog.v11.suo b/MyBlog/Blog.v11.suo
index cfd8a43..b90bb15 100644
Binary files a/MyBlog/Blog.v11.suo and b/MyBlog/Blog.v11.suo differ
diff --git a/blog.sql b/blog.sql
index 0936eb4..4f2f63e 100644
--- a/blog.sql
+++ b/blog.sql
@@ -1,32 +1,28 @@
--- phpMyAdmin SQL Dump
--- version 3.5.2
--- http://www.phpmyadmin.net
+-- MySQL dump 10.13 Distrib 5.1.69, for redhat-linux-gnu (x86_64)
--
--- 主机: localhost
--- 生成日期: 2013 年 08 月 18 日 12:42
--- 服务器版本: 5.5.25a
--- PHP 版本: 5.4.4
-
-SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-SET time_zone = "+00:00";
-
+-- Host: localhost Database: blog
+-- ------------------------------------------------------
+-- Server version 5.5.20-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
--- 数据库: `blog`
+-- Table structure for table `Article`
--
--- --------------------------------------------------------
-
---
--- 表的结构 `Article`
---
-
-CREATE TABLE IF NOT EXISTS `Article` (
+DROP TABLE IF EXISTS `Article`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Article` (
`ArticleId` int(11) NOT NULL AUTO_INCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Content` varchar(255) DEFAULT NULL,
@@ -38,85 +34,147 @@ CREATE TABLE IF NOT EXISTS `Article` (
`Status` int(11) DEFAULT NULL,
`UserId` int(11) DEFAULT NULL,
PRIMARY KEY (`ArticleId`),
- KEY `UserId` (`UserId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=3 ;
+ KEY `UserId` (`UserId`),
+ CONSTRAINT `FK379164D66426CB5F` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
--
--- 转存表中的数据 `Article`
+-- Dumping data for table `Article`
--
-INSERT INTO `Article` (`ArticleId`, `Title`, `Content`, `CreateDate`, `ModifyDate`, `CommentCount`, `Browse`, `Type`, `Status`, `UserId`) VALUES
-(2, '???', '???', '2013-08-18 00:00:00', '2013-08-18 00:00:00', 1, 1, 0, 1, NULL);
-
--- --------------------------------------------------------
+LOCK TABLES `Article` WRITE;
+/*!40000 ALTER TABLE `Article` DISABLE KEYS */;
+INSERT INTO `Article` VALUES (5,'Hello World!','This is default article,you can delte it.
\nhave a good time!
','2013-10-15 17:47:45','2013-10-15 17:47:45',1,5,0,1,2);
+/*!40000 ALTER TABLE `Article` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `ArticleExtend`
+-- Table structure for table `ArticleExtend`
--
-CREATE TABLE IF NOT EXISTS `ArticleExtend` (
+DROP TABLE IF EXISTS `ArticleExtend`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ArticleExtend` (
`ArticleExtendId` int(11) NOT NULL AUTO_INCREMENT,
`ExtendKey` varchar(255) DEFAULT NULL,
`ExtendValue` varchar(255) DEFAULT NULL,
`ArticleId` int(11) DEFAULT NULL,
PRIMARY KEY (`ArticleExtendId`),
- KEY `ArticleId` (`ArticleId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1 ;
+ KEY `ArticleId` (`ArticleId`),
+ KEY `ArticleId_2` (`ArticleId`),
+ CONSTRAINT `FK2AFB97906C15FD71` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--- --------------------------------------------------------
+--
+-- Dumping data for table `ArticleExtend`
+--
+
+LOCK TABLES `ArticleExtend` WRITE;
+/*!40000 ALTER TABLE `ArticleExtend` DISABLE KEYS */;
+/*!40000 ALTER TABLE `ArticleExtend` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `Attach`
+-- Table structure for table `Attach`
--
-CREATE TABLE IF NOT EXISTS `Attach` (
+DROP TABLE IF EXISTS `Attach`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Attach` (
`AttachId` int(11) NOT NULL AUTO_INCREMENT,
`ArticleId` int(11) DEFAULT NULL,
`Title` varchar(255) DEFAULT NULL,
`Path` varchar(255) DEFAULT NULL,
`Type` int(11) DEFAULT NULL,
PRIMARY KEY (`AttachId`),
- KEY `ArticleId` (`ArticleId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1 ;
+ KEY `ArticleId` (`ArticleId`),
+ KEY `ArticleId_2` (`ArticleId`),
+ CONSTRAINT `FK7583DA656C15FD71` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--- --------------------------------------------------------
+--
+-- Dumping data for table `Attach`
+--
+
+LOCK TABLES `Attach` WRITE;
+/*!40000 ALTER TABLE `Attach` DISABLE KEYS */;
+/*!40000 ALTER TABLE `Attach` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `Category`
+-- Table structure for table `Category`
--
-CREATE TABLE IF NOT EXISTS `Category` (
+DROP TABLE IF EXISTS `Category`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Category` (
`CategoryId` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) DEFAULT NULL,
`Type` int(11) DEFAULT NULL,
`Count` int(11) DEFAULT NULL,
`ParentId` int(11) DEFAULT NULL,
PRIMARY KEY (`CategoryId`),
- KEY `ParentId` (`ParentId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1 ;
+ KEY `ParentId` (`ParentId`),
+ KEY `ParentId_2` (`ParentId`),
+ CONSTRAINT `FK6DD211EEE8D096F` FOREIGN KEY (`ParentId`) REFERENCES `Category` (`CategoryId`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--- --------------------------------------------------------
+--
+-- Dumping data for table `Category`
+--
+
+LOCK TABLES `Category` WRITE;
+/*!40000 ALTER TABLE `Category` DISABLE KEYS */;
+INSERT INTO `Category` VALUES (1,'default',0,1,NULL);
+/*!40000 ALTER TABLE `Category` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `CategoryRelationship`
+-- Table structure for table `CategoryRelationShip`
--
-CREATE TABLE IF NOT EXISTS `CategoryRelationship` (
+DROP TABLE IF EXISTS `CategoryRelationShip`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `CategoryRelationShip` (
`RelationshipId` int(11) NOT NULL AUTO_INCREMENT,
`CategoryId` int(11) DEFAULT NULL,
`ArticleId` int(11) DEFAULT NULL,
PRIMARY KEY (`RelationshipId`),
KEY `CategoryId` (`CategoryId`),
- KEY `ArticleId` (`ArticleId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1 ;
+ KEY `ArticleId` (`ArticleId`),
+ KEY `CategoryId_2` (`CategoryId`),
+ KEY `ArticleId_2` (`ArticleId`),
+ CONSTRAINT `FK74AFA2966C15FD71` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`),
+ CONSTRAINT `FK74AFA296E5C118B3` FOREIGN KEY (`CategoryId`) REFERENCES `Category` (`CategoryId`)
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--- --------------------------------------------------------
+--
+-- Dumping data for table `CategoryRelationShip`
+--
+
+LOCK TABLES `CategoryRelationShip` WRITE;
+/*!40000 ALTER TABLE `CategoryRelationShip` DISABLE KEYS */;
+INSERT INTO `CategoryRelationShip` VALUES (3,1,5);
+/*!40000 ALTER TABLE `CategoryRelationShip` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `Comment`
+-- Table structure for table `Comment`
--
-CREATE TABLE IF NOT EXISTS `Comment` (
+DROP TABLE IF EXISTS `Comment`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Comment` (
`CommentId` int(11) NOT NULL AUTO_INCREMENT,
`Content` varchar(255) DEFAULT NULL,
`CreateDate` datetime DEFAULT NULL,
@@ -130,52 +188,59 @@ CREATE TABLE IF NOT EXISTS `Comment` (
PRIMARY KEY (`CommentId`),
KEY `UserId` (`UserId`),
KEY `ArticleId` (`ArticleId`),
- KEY `ParentId` (`ParentId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1 ;
+ KEY `ParentId` (`ParentId`),
+ KEY `UserId_2` (`UserId`),
+ KEY `ArticleId_2` (`ArticleId`),
+ KEY `ParentId_2` (`ParentId`),
+ CONSTRAINT `FK9BDE863FF792384E` FOREIGN KEY (`ParentId`) REFERENCES `Comment` (`CommentId`),
+ CONSTRAINT `FK9BDE863F6426CB5F` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`),
+ CONSTRAINT `FK9BDE863F6C15FD71` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `Comment`
+--
--- --------------------------------------------------------
+LOCK TABLES `Comment` WRITE;
+/*!40000 ALTER TABLE `Comment` DISABLE KEYS */;
+INSERT INTO `Comment` VALUES (1,'Hi,you a using NetBlog','2013-10-15 17:52:46','admin','admin@admin.com','127.0.0.1',1,2,5,NULL);
+/*!40000 ALTER TABLE `Comment` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `Setting`
+-- Table structure for table `Setting`
--
-CREATE TABLE IF NOT EXISTS `Setting` (
+DROP TABLE IF EXISTS `Setting`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Setting` (
`SettingId` int(11) NOT NULL AUTO_INCREMENT,
`SettingKey` varchar(255) DEFAULT NULL,
`SettingValue` varchar(255) DEFAULT NULL,
PRIMARY KEY (`SettingId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=35 ;
+) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--
--- 转存表中的数据 `Setting`
+-- Dumping data for table `Setting`
--
-INSERT INTO `Setting` (`SettingId`, `SettingKey`, `SettingValue`) VALUES
-(18, 'BlogTitle', '????'),
-(19, 'AllRegister', '1'),
-(20, 'DefaultRole', '1'),
-(21, 'WeekStart', '1'),
-(22, 'BlogDescription', '??????????????????'),
-(23, 'WebSite', 'GOOL.COM.CN'),
-(24, 'ArticlePageSize', '10'),
-(25, 'LastArticleCount', '10'),
-(26, 'LastCommentCount', '5'),
-(27, 'CloseComment', '0'),
-(28, 'CommentSatus', '1'),
-(29, 'NoLoginComment', '1'),
-(30, 'MaxReComment', '5'),
-(31, 'CommentPageSize', '5'),
-(32, 'AdminArticlePageSize', '10'),
-(33, 'AdminCommentPageSize', '10'),
-(34, 'AdminUserPageSize', '10');
-
--- --------------------------------------------------------
+LOCK TABLES `Setting` WRITE;
+/*!40000 ALTER TABLE `Setting` DISABLE KEYS */;
+INSERT INTO `Setting` VALUES (18,'BlogTitle','Blue container'),(19,'AllRegister','1'),(20,'DefaultRole','1'),(21,'WeekStart','1'),(22,'BlogDescription','My time is losting...'),(23,'WebSite','GOOL.COM.CN'),(24,'ArticlePageSize','10'),(25,'LastArticleCount','10'),(26,'LastCommentCount','5'),(27,'CloseComment','0'),(28,'CommentSatus','1'),(29,'NoLoginComment','1'),(30,'MaxReComment','5'),(31,'CommentPageSize','5'),(32,'AdminArticlePageSize','10'),(33,'AdminCommentPageSize','10'),(34,'AdminUserPageSize','10');
+/*!40000 ALTER TABLE `Setting` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `User`
+-- Table structure for table `User`
--
-CREATE TABLE IF NOT EXISTS `User` (
+DROP TABLE IF EXISTS `User`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `User` (
`UserId` int(11) NOT NULL AUTO_INCREMENT,
`UserName` varchar(255) DEFAULT NULL,
`Password` varchar(255) DEFAULT NULL,
@@ -185,87 +250,54 @@ CREATE TABLE IF NOT EXISTS `User` (
`Status` int(11) DEFAULT NULL,
`Role` int(11) DEFAULT NULL,
PRIMARY KEY (`UserId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=2 ;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--
--- 转存表中的数据 `User`
+-- Dumping data for table `User`
--
-INSERT INTO `User` (`UserId`, `UserName`, `Password`, `NiceName`, `Email`, `RegisterDate`, `Status`, `Role`) VALUES
-(1, 'ss22219', '303384755', '??', 'ss22219@qq.com', '2013-08-18 00:00:00', 1, 2);
-
--- --------------------------------------------------------
+LOCK TABLES `User` WRITE;
+/*!40000 ALTER TABLE `User` DISABLE KEYS */;
+INSERT INTO `User` VALUES (2,'admin','123456','admin','admin@admin.com','2013-10-15 17:43:03',0,2);
+/*!40000 ALTER TABLE `User` ENABLE KEYS */;
+UNLOCK TABLES;
--
--- 表的结构 `UserExtend`
+-- Table structure for table `UserExtend`
--
-CREATE TABLE IF NOT EXISTS `UserExtend` (
+DROP TABLE IF EXISTS `UserExtend`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `UserExtend` (
`UserExtendId` int(11) NOT NULL AUTO_INCREMENT,
`UserId` int(11) DEFAULT NULL,
`ExtendKey` varchar(255) DEFAULT NULL,
`ExtendValue` varchar(255) DEFAULT NULL,
PRIMARY KEY (`UserExtendId`),
- KEY `UserId` (`UserId`)
-) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=2 ;
-
---
--- 转存表中的数据 `UserExtend`
---
-
-INSERT INTO `UserExtend` (`UserExtendId`, `UserId`, `ExtendKey`, `ExtendValue`) VALUES
-(1, 1, 'Cover', 'http://img.baidu.com/img/iknow/avarta/66/r6s1g1.gif');
-
---
--- 限制导出的表
---
-
---
--- 限制表 `Article`
---
-ALTER TABLE `Article`
- ADD CONSTRAINT `FK873F04FBE7840C6E` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`);
-
---
--- 限制表 `ArticleExtend`
---
-ALTER TABLE `ArticleExtend`
- ADD CONSTRAINT `FK705E406EB4128634` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`);
-
---
--- 限制表 `Attach`
---
-ALTER TABLE `Attach`
- ADD CONSTRAINT `FK33C9C03EB4128634` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`);
-
---
--- 限制表 `Category`
---
-ALTER TABLE `Category`
- ADD CONSTRAINT `FK6482F241E5F0AE1` FOREIGN KEY (`ParentId`) REFERENCES `Category` (`CategoryId`);
-
---
--- 限制表 `CategoryRelationship`
---
-ALTER TABLE `CategoryRelationship`
- ADD CONSTRAINT `FK24112662B4128634` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`),
- ADD CONSTRAINT `FK24112662A6C14A26` FOREIGN KEY (`CategoryId`) REFERENCES `Category` (`CategoryId`);
+ KEY `UserId` (`UserId`),
+ KEY `UserId_2` (`UserId`),
+ CONSTRAINT `FKBE0D2EE56426CB5F` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
--
--- 限制表 `Comment`
+-- Dumping data for table `UserExtend`
--
-ALTER TABLE `Comment`
- ADD CONSTRAINT `FKE2466703F002AFC9` FOREIGN KEY (`ParentId`) REFERENCES `Comment` (`CommentId`),
- ADD CONSTRAINT `FKE2466703B4128634` FOREIGN KEY (`ArticleId`) REFERENCES `Article` (`ArticleId`),
- ADD CONSTRAINT `FKE2466703E7840C6E` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`);
---
--- 限制表 `UserExtend`
---
-ALTER TABLE `UserExtend`
- ADD CONSTRAINT `FK41993EB172A82051` FOREIGN KEY (`UserExtendId`) REFERENCES `User` (`UserId`),
- ADD CONSTRAINT `FK41993EB1E7840C6E` FOREIGN KEY (`UserId`) REFERENCES `User` (`UserId`);
+LOCK TABLES `UserExtend` WRITE;
+/*!40000 ALTER TABLE `UserExtend` DISABLE KEYS */;
+/*!40000 ALTER TABLE `UserExtend` ENABLE KEYS */;
+UNLOCK TABLES;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2013-10-15 17:55:57