public HttpResponseMessage NewPost(string post) { var success = false; var message = string.Empty; var userId = -1; var moduleId = this.Request.FindModuleId(); var tabId = this.Request.FindTabId(); var moduleSettings = new ShoutBoxModuleSettings(moduleId, tabId); if (this.UserInfo != null && this.UserInfo.UserID > 0) { userId = this.UserInfo.UserID; } //validate the post for profanity if (ValidatePostForProfanity(post)) { var floodControl = new FloodControl(this.Request.FindModuleId(), this.Request.FindTabId(), this.Request.GetIPAddress(), this.UserInfo); if (floodControl.AllowNewPost()) { success = true; _repository.AddPost(new ShoutPost() { ModuleId = moduleId, CreatedDate = DateTime.Now, VoteDown = 0, VoteUp = 0, UserId = userId > 0 ? (int?)userId : null, Message = post }); Log.Debug("New post has been saved"); } else { Log.WarnFormat("Flood control block the new post. The IP:{0} has already posted a new item in the time limit window", this.Request.GetIPAddress()); message = message = Localization.GetString("FloodControlNewPost.Text", SharedResource); } } else { Log.WarnFormat("The new post was not saved due to profanity. The IP:{0}", this.Request.GetIPAddress()); message = Localization.GetString("ProfanityBanned.Text", SharedResource); } var posts = _repository .GetDisplayPosts(moduleId, moduleSettings.NumberOfPostsToReturn); return Request.CreateResponse(new { success = success, message = message, data = new { posts = posts.ToArray() } }); }
public HttpResponseMessage VoteDown(int itemId) { var floodControl = new FloodControl(this.Request.FindModuleId(), this.Request.FindTabId(), this.Request.GetIPAddress(), this.UserInfo); if (floodControl.AllowVote(itemId)) { var currentDownVote = _repository .VoteDown(itemId); Log.DebugFormat("Vote down recorded, IP:{0}, itemId:{1}", this.Request.GetIPAddress(), itemId); return Request.CreateResponse(new { success = true, data = new { voteDown = currentDownVote } }); } else { Log.WarnFormat("Flood control block the vote. The IP:{0} has already voted on this item:{1} in the time limit window", this.Request.GetIPAddress(), itemId); return Request.CreateResponse(new { success = false }); } }