// Important Terms // isenabled // ........... 1: Enabled // ........... 0: Disabled // isapproved // ........... 1: Approved / Reviewed // ........... 0: Not approved, reviewed yet // isadult // ........... 1: Adult Oriented // ........... 0: Normal Post // isresolved // ........... 1: Resolved Topic // ........... 0: Unresolved Topic // Type // ........... 0: Normal Posts // ........... 1: Announcements // islocked // ........... 0: Normal // ........... 1: Locked Post (No reply to post) #region ActionScript public static void Validation(JGN_ForumTopics gal) { // validation if (gal.title != null && gal.title.Length > 200) { gal.title = gal.title.Substring(0, 199); } if (gal.tags != null && gal.tags.Length > 300) { gal.tags = gal.tags.Substring(0, 299); } }
public async Task <ActionResult> proc() { var json = new StreamReader(Request.Body).ReadToEnd(); var model = JsonConvert.DeserializeObject <JGN_ForumTopics>(json); // new topic posted if (model.replyid == 0) { // check title if (model.title.Length < 5) { return(Ok(new { status = "error", message = SiteConfig.generalLocalizer["_invalid_title"].Value })); } } // Add information in table var topics = new JGN_ForumTopics(); if (model.id > 0) { topics.id = model.id; } string content = UGeneral.SanitizeText(model.description); topics.description = content; topics.title = model.title; if (topics.title.Length > 200) { topics.title = topics.title.Substring(0, 199); } topics.tags = model.tags; topics.forumid = model.forumid; topics.userid = model.userid; int isapproved = 1; topics.isapproved = (byte)isapproved; topics.isenabled = 1; topics.replyid = model.replyid; topics = await ForumTopicBLL.Process(_context, topics, true); if (model.tags != "" && model.replyid == 0 && model.id == 0) { // Process tags TagsBLL.Process_Tags(_context, model.tags, TagsBLL.Types.Forums, 0); } // Mail Procesing Section if (model.id == 0 && model.replyid == 0) { // ProcessMail(tid, topics.replyid, topics.username, model.GroupID, model.Description, model.Title); // add newly added topic id in struct for user activity and group posting //topics.id = topics.id; } topics.url = Forum_Urls.Prepare_Topic_Url(topics.id, topics.title, true); topics.author_url = UserUrlConfig.ProfileUrl(topics.author, Jugnoon.Settings.Configs.RegistrationSettings.uniqueFieldOption); return(Ok(new { status = "success", record = topics, message = SiteConfig.generalLocalizer["_record_created"].Value })); }
public async Task <IActionResult> post(PostTopicViewModel model) { if (ModelState.IsValid) { // new topic posted if (model.ReplyID == 0) { // check title if (model.Title.Length < 10) { model.Message = SiteConfig.forumLocalizer["_forum_post_msg_09"].Value; return(View(model)); } if (UtilityBLL.isLongWordExist(model.Title) || UtilityBLL.isLongWordExist(model.Title)) { model.Message = SiteConfig.generalLocalizer["_invalid_title"]; return(View(model)); } } // Add information in table var topics = new JGN_ForumTopics(); if (model.TopicID > 0) { topics.id = model.TopicID; } topics.forumid = model.ForumID; string content = UGeneral.SanitizeText(model.Description); // Process Contents -> links, bbcodes etc // content = UtilityBLL.Process_Content_Text(content); // Generate Album Preview //content = AlbumsBLL.Generate_Blog_Gallery_Previews(content); topics.description = content; if (model.ReplyID > 0) { var _lst = await ForumTopicBLL.LoadItems(_context, new ForumTopicEntity() { id = model.TopicID, loadall = true }); if (_lst.Count > 0) { topics.tags = _lst[0].tags; topics.title = _lst[0].title; topics.forumid = _lst[0].forumid; if (topics.title.Length > 200) { topics.title = topics.title.Substring(0, 199); } } } else { if (model.Tags != null) { topics.tags = model.Tags; if (topics.tags.Length > 300) { topics.tags = topics.tags.Substring(0, 299); } } topics.title = model.Title; } topics.userid = model.UserName; int isapproved = 1; if (Jugnoon.Settings.Configs.GeneralSettings.content_approval == 0 && !model.isAdmin && model.ReplyID == 0) { isapproved = 0; // manual approval } topics.isapproved = (byte)isapproved; topics.isenabled = 1; topics.replyid = model.ReplyID; topics = await ForumTopicBLL.Process(_context, topics, model.isAdmin); if (model.Tags != "") { // Process tags TagsBLL.Process_Tags(_context, model.Tags, TagsBLL.Types.Forums, 0); } // Mail Procesing Section if (model.TopicID == 0 && model.ReplyID == 0) { ProcessMail(topics.id, topics.replyid, topics.userid, model.GroupID, model.Description, model.Title); // add newly added topic id in struct for user activity and group posting //topics.topicid = topics.topicid; } if (model.ReplyID > 0) { // topic is posted in reply // redirect to topic return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.replyid, topics.title, model.isAdmin) + "?status=posted")); } return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.id, topics.title, model.isAdmin) + "?status=posted")); } // initialize values if (model.ForumID == 0) { model.ForumList = await ForumBLLC.LoadItems(_context, new ForumEntity() { loadall = true, iscache = true }); } model.Message = "Validation Error"; return(View(model)); }
public static async Task <JGN_ForumTopics> Process(ApplicationDbContext context, JGN_ForumTopics entity, bool isadmin) { if (entity.id == 0) { Validation(entity); var _entity = new JGN_ForumTopics() { forumid = entity.forumid, title = UtilityBLL.processNull(entity.title, 0), description = UtilityBLL.processNull(entity.description, 0), tags = UtilityBLL.processNull(entity.tags, 0), userid = entity.userid, isenabled = entity.isenabled, isapproved = entity.isapproved, created_at = DateTime.Now, replyid = entity.replyid, lastpostdate = DateTime.Now, isadult = entity.isadult }; context.Entry(_entity).State = EntityState.Added; await context.SaveChangesAsync(); entity = _entity; // update statistics // if topic is approved and enabled if (entity.isapproved == 1 && entity.isenabled == 1) { // update user stats var total_posts = await CountRecords(context, new ForumTopicEntity() { userid = entity.userid, isenabled = EnabledTypes.All, isapproved = ApprovedTypes.All }); await UserStatsBLL.Update_Field(context, entity.userid, (short)total_posts, "stat_forum_topics"); // update post stats if (entity.replyid > 0) { // update topic post stats // e.g // replies (total replies) // lastpostdatetime // lastpostusername await Update_Topic_Stats(context, entity); // no need to update posts in case of reply } else { //update thread stats try { int threads = await CountRecords(context, new ForumTopicEntity() { forumid = entity.forumid, replyid = 0, ispublic = true }); ForumBLLC.Update_Value_V3(context, entity.forumid, "threads", threads); } catch (Exception ex) { var ms = ex.Message; } int posts = await CountRecords(context, new ForumTopicEntity() { forumid = entity.forumid, replyid = 0, ispublic = true, onlytopics = false // replyid = 0; }); ForumBLLC.Update_Value_V3(context, entity.forumid, "posts", posts); // update lastpost time, last post id (only if new topic posted ForumBLLC.Update_Last_Post(context, entity.forumid, _entity.id); } // update points //int total_points = Convert.ToInt32(UserBLL.Return_Value(entity.userid, "stat_forum_points")); //total_points = total_points + Forum_Settings.TopicReplyPoints; //UserBLL.Update_Field_V3(context, entity.userid, "stat_forum_points", total_points); // send notification mail to admin if (!isadmin) { // MailProcess.Admin_New_Content_Added(context, entity.userid, "forum topic", ""); } } } else { var item = context.JGN_ForumTopics .Where(p => p.id == entity.id) .FirstOrDefault <JGN_ForumTopics>(); item.forumid = entity.forumid; //item.title = UtilityBLL.processNull(entity.title,0); item.description = UtilityBLL.processNull(entity.description, 0); //item.tags = UtilityBLL.processNull(entity.tags, 0); item.isenabled = (byte)entity.isenabled; item.isapproved = (byte)entity.isapproved; context.SaveChanges(); } return(entity); }
// update user topic post stats public static async Task <bool> Update_Topic_Stats(ApplicationDbContext context, JGN_ForumTopics entity) { // increment topic replies int replies = await CountRecords(context, new ForumTopicEntity() { replyid = entity.replyid, ispublic = true, }); replies--; // it count both topic and replies (deduct topic) var item = context.JGN_ForumTopics .Where(p => p.id == entity.replyid) .FirstOrDefault(); item.replies = replies; item.lastpostdate = DateTime.Now; item.lastpostuserid = entity.userid; context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); return(true); }