public int MarkFlagOnForum(ForumFlaggedModel objectModel) { int returnValue = -1; tblFlagComment tblFlagCommentDb = new tblFlagComment(); if (objectModel.ForumMessageType == "topic") { tblFlagCommentDb.TopicId = objectModel.AutoId; } else { tblFlagCommentDb.ReplyId = objectModel.AutoId; } tblFlagCommentDb.Message = objectModel.Comment.Trim(); tblFlagCommentDb.CreatedBy = ClientSessionData.UserClientId; tblFlagCommentDb.CreatedFromIP = HttpContext.Current.Request.UserHostAddress; tblFlagCommentDb.CreatedOn = DateTime.UtcNow; context.tblFlagComments.Add(tblFlagCommentDb); int count = context.SaveChanges(); if (count == 1) { if (objectModel.ForumMessageType == "topic") { tblForum tblForumDb = new tblForum(); tblForumDb = context.tblForums.Where(x => x.TopicId == objectModel.AutoId).FirstOrDefault(); tblForumDb.IsFlagged = true; context.tblForums.Attach(tblForumDb); context.Entry(tblForumDb).Property(x => x.IsFlagged).IsModified = true; count = context.SaveChanges(); if (count == 1) { returnValue = 0; } } else if (objectModel.ForumMessageType == "reply") { tblForumReply tblForumReplyDb = new tblForumReply(); tblForumReplyDb = context.tblForumReplies.Where(x => x.ReplyId == objectModel.AutoId).FirstOrDefault(); tblForumReplyDb.IsFlagged = true; context.tblForumReplies.Attach(tblForumReplyDb); context.Entry(tblForumReplyDb).Property(x => x.IsFlagged).IsModified = true; count = context.SaveChanges(); if (count == 1) { returnValue = 0; } } else { returnValue = -2; } } return(returnValue); }
public JsonResult AddFlagOnTopic(ForumFlaggedModel model) { int result = -1; string strMsg = ""; try { if (String.IsNullOrEmpty(model.ForumMessageType) || model.ForumMessageType.Trim() == "") { result = -4; strMsg = "Error! Try again later."; } else if (model.AutoId <= 0) { result = -5; strMsg = "Error! Try again later."; } else if (String.IsNullOrEmpty(model.Comment) || model.Comment.Trim() == "") { result = -2; strMsg = "Comment required."; } else { ForumHelper helper = new ForumHelper(); int returnValue = helper.MarkFlagOnForum(model); if (returnValue == 0) { strMsg = "You have flagged it successfully."; result = 0; } else { strMsg = "Error! Try again later."; result = -3; } } } catch (Exception ex) { strMsg = "Exception: " + ex.Message; } return(Json(new { counter = result, msg = strMsg, autoid = model.AutoId, type = model.ForumMessageType, userRole = ClientSessionData.ClientRoleName.ToLower() }, JsonRequestBehavior.AllowGet)); }
public List <ForumFlaggedModel> GetFlaggedForumMessage(long id, string type) { var forumFlagMessageList = context.vw_GetFlaggedMessage.Where(x => x.AutoId == id && x.ForumMessageType == type).ToList(); List <ForumFlaggedModel> objForumReplyListingModel = new List <ForumFlaggedModel>(); foreach (var item in forumFlagMessageList) { ForumFlaggedModel replyList = new ForumFlaggedModel { TopicId = item.TopicId.Value, ReplyId = item.ReplyId.Value, Comment = item.Message, CreatedOn = item.CreatedOn.Value, CreatedDate = item.CreatedDate, CreatedTime = item.CreatedTime, CreatedDateTime = item.CreatedDateTime, CreatedBy = item.CreatedBy.ToString(), CreatorName = item.CreatorName, CreatorEmailId = item.CreatorEmailId }; objForumReplyListingModel.Add(replyList); } return(objForumReplyListingModel); }