protected KLAuthor GetAuthor(int newsID) { var News = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault(); var author = new KLAuthor(News.AuthorID); return(author); }
protected void listviewComment_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.Item != null) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; Label lbCommentID = (Label)e.Item.FindControl("CommentID"); try { KLNewsComment com = new KLNewsComment(int.Parse(lbCommentID.Text)); KLNews news = new KLNews(com.NewsID, 0); if (String.Equals(e.CommandName.ToLower(), "approve")) { news.CommentCount = news.CommentCount + 1; com.IsPublish = true; } else if (String.Equals(e.CommandName.ToLower(), "delete")) { int index = e.Item.DisplayIndex; listviewComment.DeleteItem(index); news.CommentCount = news.CommentCount - 1; com.IsPublish = false; com.ISDel = true; } news.Save(); com.Save(); } catch (Exception) { } } WebUtils.SetupRedirect(this, Request.RawUrl); }
private string UpdateLike(int newsID) { bool isSuccess = false; var newsHistory = KLLikeHistory.GetAll().Where(h => h.NewsID == newsID && h.AuthorID == GetAuthor(currentUser.UserId)).SingleOrDefault(); if (newsHistory == null) { newsHistory = new KLLikeHistory(); newsHistory.NewsID = newsID; newsHistory.AuthorID = GetAuthor(currentUser.UserId); newsHistory.CreateDate = DateTime.Now; newsHistory.Save(); var news = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault(); news.LikeCount += 1; isSuccess = news.Save(); } else { KLLikeHistory.Delete(newsHistory.LikeID); var news = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault(); news.LikeCount -= 1; isSuccess = news.Save(); } return(isSuccess ? "success" : "fail"); }
private string UpdateShare(int newsID) { var news = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault(); news.ShareCount += 1; bool res = news.Save(); return(res ? "success" : "fail"); }
private void LoadParams() { authorID = WebUtils.ParseInt32FromQueryString("id", authorID); if (authorID > -1) { author = new KLAuthor(authorID); } pagenum = WebUtils.ParseInt32FromQueryString("page", pagenum); news = KLNews.GetPageByAuthor(pagenum, pageSize, out totalPage, author.AuthorID, "", false, true, false).ToList(); }
private void PopulateControls() { List <KLNews> lst = KLNews.GetPageByAuthor(1, 10000, out totalpage, author.AuthorID, "", false, true, false); foreach (var item in lst) { News temp = new News(siteSettings.SiteId, item.NewsID); item.Title = temp.Title; item.Datepost = temp.StartDate; } ddlnew.DataSource = lst; ddlnew.DataBind(); ddlnew.SelectedValue = news.ToString(); }
protected void Page_Load(object sender, EventArgs e) { LoadSettings(); //totalPages = News.GetCountBySearch(siteSettings.SiteId, zoneId.ToString(), config.NewsType, -1, null, -1, -1, -1, null, null, null, null, null, string.Empty); int totalRow = News.GetCount(siteSettings.SiteId, -1, -1, -1, -1); lstNewsTop5 = News.GetPageBySearch(siteSettings.SiteId, null, 0, 1, null, -1, -1, -1, null, null, null, null, null, -1, -1, string.Empty, 1, totalRow).OrderByDescending(n => n.Viewed).Take(5).ToList(); lstNewsMostOfWeek = GetNewsMostOfWeek(); lstAuthorMostArticle = KLAuthor.GetAll().Where(a => a.IsActive == true).OrderByDescending(n => n.ArticleCount).Take(10).ToList(); if (like > 0) { KLNews news = KLNews.GetAll().Where(n => n.NewsID == like).SingleOrDefault(); news.LikeCount += 1; news.Save(); } }
private void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { grid.PagerStyle.EnableSEOPaging = false; bool isApplied = gridPersister.IsAppliedSortFilterOrGroup; int iCount = KLNews.GetCount(); int startRowIndex = isApplied ? 1 : grid.CurrentPageIndex + 1; int maximumRows = isApplied ? iCount : grid.PageSize; grid.VirtualItemCount = iCount; grid.AllowCustomPaging = !isApplied; List <KLNews> lst = KLNews.GetPageByAuthor(startRowIndex, maximumRows, out iCount, author.AuthorID, "", isdraft, isapproved, all); foreach (var item in lst) { News temp = new News(siteSettings.SiteId, item.NewsID); item.Title = temp.Title; item.Datepost = temp.StartDate; } grid.DataSource = lst; }
private void LoadSettings() { currentUser = SiteUtils.GetCurrentSiteUser(); newsID = WebUtils.ParseInt32FromQueryString("newsID", newsID); siteSettings = CacheHelper.GetCurrentSiteSettings(); timeOffset = SiteUtils.GetUserTimeOffset(); timeZone = SiteUtils.GetUserTimeZone(); if (currentUser == null) { imgAvatar.ImageUrl = "/Data/Sites/1/Author/Authordefault.png"; currentUser = SiteUser.GetByEmail(siteSettings, "*****@*****.**"); } else { author = KLAuthor.GetKLAuthorByUserID(currentUser.UserId); imgAvatar.ImageUrl = AuthorHepper.MediaFolderPath(1, author.UserID) + author.Avatar; txtEmail.Text = currentUser.Email; txtFullName.Text = currentUser.Name; } news = new KLNews(newsID, 0); }
protected virtual void LoadSettings() { currentUser = SiteUtils.GetCurrentSiteUser(); if (currentUser == null) { WebUtils.SetupRedirect(this, SiteRoot); } if (newsId > -1) { news = new News(siteSettings.SiteId, newsId); if (news != null && news.NewsID > 0) { KLnews = new KLNews(news.NewsID, 0); if (news.IsDeleted) { SiteUtils.RedirectToEditAccessDeniedPage(); return; } newsType = news.NewsType; imageFolderPath = NewsHelper.MediaFolderPath(siteSettings.SiteId, news.NewsID); } } shortcontent.ImageManager.ViewPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; shortcontent.ImageManager.UploadPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; shortcontent.ImageManager.DeletePaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; fullcontent.ImageManager.ViewPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; fullcontent.ImageManager.UploadPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; fullcontent.ImageManager.DeletePaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) }; FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p != null) { fileSystem = p.GetFileSystem(); } }
private int Save(string op = "") { Page.Validate("news"); if (!Page.IsValid) { return(-1); } if (ddlnewtype.SelectedValue.Length == 0) { message.ErrorMessage = CustomResources.SelectTypeMessage; return(-1); } if (news == null) { news = new News(siteSettings.SiteId, newsId); news.ZoneID = -1; } if (currentUser == null) { return(-1); } news.LastModUserGuid = currentUser.UserGuid; news.SiteId = siteSettings.SiteId; news.FullContent = fullcontent.Content; news.BriefContent = shortcontent.Content; news.Title = newstitle.Text; news.UserGuid = currentUser.UserGuid; if (news.Save()) { if (newsId > 0) { KLnews.NewType = Convert.ToInt32(ddlnewtypechild.SelectedValue); LogActivity.Write("Update news", news.Title); message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "UpdateSuccessMessage"); } else { KLAuthor author = KLAuthor.GetKLAuthorByUserID(currentUser.UserId); KLnews = new KLNews() { CommentCount = 0, AuthorID = author.AuthorID, LikeCount = 0, Newlsevel = 1, Newstotalpoint = 0, NewsID = news.NewsID, ShareCount = 0, NewType = Convert.ToInt32(ddlnewtypechild.SelectedValue), ViewCount = 0, }; } if (op == "draft") { KLnews.Isdraft = true; KLnews.Isapproved = false; } else { KLnews.Isdraft = false; KLnews.Isapproved = false; } if (KLnews.Save()) { LogActivity.Write("Create new news", news.Title); message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "InsertSuccessMessage"); } } SiteUtils.QueueIndexing(); return(news.NewsID); }
void btnUpdate_Click(object sender, EventArgs e) { try { if (!NewsPermission.CanUpdate) { SiteUtils.RedirectToEditAccessDeniedPage(); return; } bool isUpdated = false; foreach (GridDataItem data in grid.Items) { //TextBox txtDisplayOrder = (TextBox)data.FindControl("txtDisplayOrder"); //TextBox txtViewed = (TextBox)data.FindControl("txtViewed"); CheckBox cbIsPublished = (CheckBox)data.FindControl("cbPublished"); int newsId = Convert.ToInt32(data.GetDataKeyValue("NewsID")); int number_news = 0; //int displayOrder = Convert.ToInt32(data.GetDataKeyValue("DisplayOrder")); //int viewed = Convert.ToInt32(data.GetDataKeyValue("Viewed")); bool isPublished = Convert.ToBoolean(data.GetDataKeyValue("IsPublished")); //int displayOrderNew = displayOrder; //int.TryParse(txtDisplayOrder.Text, out displayOrderNew); //int viewedNew = viewed; //int.TryParse(txtViewed.Text, out viewedNew); //|| viewed != viewedNew //displayOrder != displayOrderNew || if (cbIsPublished.Checked != isPublished) { News objNews = new News(SiteId, newsId); KLNews klNews = KLNews.GetAll().Where(n => n.NewsID == newsId).FirstOrDefault(); KLAuthor author = new KLAuthor(klNews.AuthorID); if (objNews != null && objNews.NewsID > -1) { if (cbIsPublished.Checked == true) { if (author != null && author.AuthorID > -1 && objNews.IsPublished == false) { number_news = author.ArticleCount = (author.ArticleCount + 1); author.LevelAuthor = UpdateLevel(number_news); author.Save(); klNews.Isapproved = true; klNews.Save(); } ApproveArticle(objNews.NewsID); } else { if (objNews.IsPublished == true) { number_news = author.ArticleCount = (author.ArticleCount - 1); author.LevelAuthor = UpdateLevel(number_news); author.Save(); klNews.Isapproved = false; insertnotify(author.UserID, klNews.NewsID, objNews.Title); klNews.Save(); } } objNews.IsPublished = cbIsPublished.Checked; // objNews.DisplayOrder = displayOrderNew; //objNews.Viewed = viewedNew; objNews.Save(); LogActivity.Write("Resort news", objNews.Title); isUpdated = true; } } } if (isUpdated) { grid.Rebind(); message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "UpdateSuccessMessage"); } } catch (Exception ex) { log.Error(ex); } }