Esempio n. 1
0
 protected void ibDelete_Click(object sender, ImageClickEventArgs e)
 {
     blog = new Blog();
     if (ViewState["BlogID"] != null)
         blog.BlogID = (long)ViewState["BlogID"];
     _presenter.Delete(blog);
 }
Esempio n. 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!");
            }
        }
Esempio n. 3
0
 public void DeleteBlog(Blog blog)
 {
     using (SPKTDataContext dc = _conn.GetContext())
     {
         dc.Blogs.Attach(blog, true);
         dc.Blogs.DeleteOnSubmit(blog);
         dc.SubmitChanges();
     }
 }
Esempio n. 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;
        }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 8
0
 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);
 }
Esempio n. 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();
             }
         }
     }
 }
Esempio n. 10
0
 private Blog CleanPageName(Blog blog)
 {
     blog.PageName = blog.PageName.Replace(" ", "-").Replace("!", "")
         .Replace("&", "").Replace("?", "").Replace(",", "");
     return blog;
 }
Esempio n. 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;
 }
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
 internal void Delete(Blog blog)
 {
     _blogRepository.DeleteBlog(blog);
 }