示例#1
0
文件: Post.aspx.cs 项目: SPKT/MHX2
 protected void ibDelete_Click(object sender, ImageClickEventArgs e)
 {
     blog = new Blog();
     if (ViewState["BlogID"] != null)
         blog.BlogID = (long)ViewState["BlogID"];
     _presenter.Delete(blog);
 }
示例#2
0
        public void SavePost(Blog blog)
        {
            bool result = _blogRepository.CheckPageNameIsUnique(blog);
            if (result)
            {
                blog.AccountID = _webContext.CurrentUser.AccountID;
                if (blog.BlogID > 0)
                {
                    Blog orginBlog = _blogRepository.GetBlogByBlogID(blog.BlogID);
                    orginBlog.Title = blog.Title;
                    orginBlog.Subject = blog.Subject;
                    orginBlog.PageName = blog.PageName;
                    orginBlog.IsPublished = blog.IsPublished;
                    orginBlog.Post = blog.Post;
                    _blogRepository.SaveBlog(orginBlog);
                    _alertService.AddUpdatedBlogPostAlert(blog);
                    _redirector.GoToViewBlogPost(orginBlog.BlogID);
                }
                else
                {
                    long id =_blogRepository.SaveBlog(blog);
                    _alertService.AddNewBlogPostAlert(blog);
                    _redirector.GoToViewBlogPost(id);
                }

            }
            else
            {
                _view.ShowError("Tên bài viết đã tồn tại!");
            }
        }
示例#3
0
 public void DeleteBlog(Blog blog)
 {
     using (SPKTDataContext dc = _conn.GetContext())
     {
         dc.Blogs.Attach(blog, true);
         dc.Blogs.DeleteOnSubmit(blog);
         dc.SubmitChanges();
     }
 }
示例#4
0
        public Blog GetBlogByPageName(string PageName, Int32 AccountID)
        {
            Blog result = new Blog();

            using (SPKTDataContext dc = _conn.GetContext())
            {
                result = dc.Blogs.Where(b => b.PageName == PageName && b.AccountID == AccountID).FirstOrDefault();
            }

            return result;
        }
示例#5
0
 public Blog GetBlogByBlogID(Int64 BlogID)
 {
     Blog result = new Blog();
     using (SPKTDataContext dc = _conn.GetContext())
     {
         result = dc.Blogs.Where(b => b.BlogID == BlogID).FirstOrDefault();
         Account account = dc.Accounts.Where(a => a.AccountID == result.AccountID).FirstOrDefault();
         result.Account = account;
     }
     return result;
 }
示例#6
0
 public bool CheckPageNameIsUnique(Blog blog)
 {
     blog = CleanPageName(blog);
     bool result = true;
     using (SPKTDataContext dc = _conn.GetContext())
     {
         int count = dc.Blogs.Where(b => b.PageName == blog.PageName && b.AccountID == blog.AccountID).Count();
         if (count > 0)
             result = false;
     }
     return result;
 }
示例#7
0
 public void AddNewBlogPostAlert(Blog blog)
 {
     alert = new Alert();
     alert.CreateDate = DateTime.Now;
     alert.AccountID = _userSession.CurrentUser.AccountID;
     alert.AlertTypeID = (int)AlertType.AlertTypes.NewBlogPost;
     alertMessage = "<div class=\"AlertHeader\">" + GetProfileImage(_userSession.CurrentUser.AccountID) +
                    GetProfileUrl(_userSession.CurrentUser.UserName) + " has just added a new blog post: <b>" +
                    blog.Title + "</b></div>";
     alert.Message = alertMessage;
     SaveAlert(alert);
     SendAlertToFriends(alert);
 }
示例#8
0
文件: Post.aspx.cs 项目: SPKT/MHX2
 protected void btnSave_Click(object sender, EventArgs e)
 {
     blog = new Blog();
     if (ViewState["BlogID"] != null)
         blog.BlogID = (long)ViewState["BlogID"];
     blog.Title = txtTitle.Text;
     blog.Subject = txtSubject.Text;
     blog.PageName = txtTitle.Text;
     blog.IsPublished = ckPubic.Checked;
     blog.Post = editBody.Content;
     if (ViewState["CreatedDate"] != null)
         blog.CreateDate = (DateTime)ViewState["CreatedDate"];
     _presenter.SavePost(blog);
 }
示例#9
0
 public void Init(IViewPost View)
 {
     _view = View;
     blog=_blogRepository.GetBlogByBlogID(_webContext.BlogID);
     if(blog!=null)
     {
         _view.LoadPost(blog);
         if (_userSession.LoggedIn)
         {
             if (blog.AccountID == _userSession.CurrentUser.AccountID)
             {
                 _view.DisplayEdit();
             }
         }
     }
 }
示例#10
0
 private Blog CleanPageName(Blog blog)
 {
     blog.PageName = blog.PageName.Replace(" ", "-").Replace("!", "")
         .Replace("&", "").Replace("?", "").Replace(",", "");
     return blog;
 }
示例#11
0
 public Int64 SaveBlog(Blog blog)
 {
     blog = CleanPageName(blog);
     string post = blog.Post.Replace("<body>", "").Replace("<br /></body>", "").Replace("<html>", "")
         .Replace("</html>", "").Replace("<head>", "").Replace("</head>", "");
     blog.Post = post;
     using (SPKTDataContext dc = _conn.GetContext())
     {
         if (blog.BlogID > 0)
         {
             blog.UpdateDate = DateTime.Now;
             dc.Blogs.Attach(blog, true);
         }
         else
         {
             blog.CreateDate = DateTime.Now;
             blog.UpdateDate = DateTime.Now;
             dc.Blogs.InsertOnSubmit(blog);
         }
         dc.SubmitChanges();
     }
     return blog.BlogID;
 }
示例#12
0
文件: AlertService.cs 项目: SPKT/MHX2
 public void AddUpdatedBlogPostAlert(Blog blog)
 {
     Init();
     alert = new Alert();
     alert.CreateDate = DateTime.Now;
     alert.AccountID = _userSession.CurrentUser.AccountID;
     alert.AlertTypeID = (int)AlertType.AlertTypes.NewBlogPost;
     alertMessage = "<div >" + GetProfileImage(_userSession.CurrentUser.AccountID) +
                    GetProfileUrl(_userSession.CurrentUser.UserName) + " vừa mới cập nhật <b>" + "<a href=\"" + _webContext.RootUrl + "Blogs/ViewBlog" + ".aspx?BlogID=" + blog.BlogID + "\">" +
                    blog.Title + "</a>" +
                    "!</div>";
     alert.Message = alertMessage;
     SaveAlert(alert);
     SendAlertToFriends(alert);
 }
示例#13
0
 internal void Delete(Blog blog)
 {
     _blogRepository.DeleteBlog(blog);
 }