//public BasicJsonMessage<Topic> PostNewTopic(Forum forum, User user, ForumPermissionContext permissionContext, NewPost newPost, string ip, string userUrl, Func<Topic, string> topicLinkGenerator) //{ //} public Topic PostNewTopic(Forum forum, User user, ForumPermissionContext permissionContext, NewPost newPost, string ip, string userUrl, Func <Topic, string> topicLinkGenerator) { if (!permissionContext.UserCanPost || !permissionContext.UserCanView) { throw new Exception($"User {user.Name} can't post to forum {forum.Title}."); } newPost.Title = _textParsingService.Censor(newPost.Title); // TODO: text parsing is controller, see issue #121 https://github.com/POPWorldMedia/POPForums/issues/121 var urlName = newPost.Title.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newPost.Title.ToUrlName())); var timeStamp = DateTime.UtcNow; var topicID = _topicRepository.Create(forum.ForumID, newPost.Title, 0, 0, user.UserID, user.Name, user.UserID, user.Name, timeStamp, false, false, false, urlName); var postID = _postRepository.Create(topicID, 0, ip, true, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, timeStamp, false, user.Name, null, false, 0); _forumRepository.UpdateLastTimeAndUser(forum.ForumID, timeStamp, user.Name); _forumRepository.IncrementPostAndTopicCount(forum.ForumID); _profileRepository.SetLastPostID(user.UserID, postID); var topic = new Topic { TopicID = topicID, ForumID = forum.ForumID, IsClosed = false, IsDeleted = false, IsPinned = false, LastPostName = user.Name, LastPostTime = timeStamp, LastPostUserID = user.UserID, ReplyCount = 0, StartedByName = user.Name, StartedByUserID = user.UserID, Title = newPost.Title, UrlName = urlName, ViewCount = 0 }; // <a href="{0}">{1}</a> started a new topic: <a href="{2}">{3}</a> var topicLink = topicLinkGenerator(topic); var message = String.Format(Resources.NewPostPublishMessage, userUrl, user.Name, topicLink, topic.Title); var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(forum.ForumID).Count > 0; _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewTopic, forumHasViewRestrictions); _eventPublisher.ProcessEvent(String.Empty, user, EventDefinitionService.StaticEventIDs.NewPost, true); forum = _forumRepository.Get(forum.ForumID); _broker.NotifyForumUpdate(forum); _broker.NotifyTopicUpdate(topic, forum, topicLink); _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID }); return(topic); }
public async Task <IActionResult> Create([FromBody] TopicCreateDTO topicCreateDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo(LogMessages.AttemptedToCreate(location)); if (topicCreateDTO == null) { _logger.LogWarn(LogMessages.EmptyRequest(location)); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn(LogMessages.IncompleteData(location)); return(BadRequest(ModelState)); } var topic = _mapper.Map <Topic>(topicCreateDTO); var isSuccess = await _topicRepository.Create(topic); if (!isSuccess) { return(InternalError(LogMessages.CreateFailed(location))); } _logger.LogInfo(LogMessages.Success(location)); _logger.LogInfo($"{topic}"); return(Created("Create", new { topic })); } catch (Exception e) { return(InternalError(LogMessages.InternalError(location, e.Message, e.InnerException))); } }
public Operation <TopicModel> Create(TopicModel model) { return(Operation.Create(() => { model.Validate(); return _post.Create(model); })); }
public ActionResult <Topic> Post(string name) { Topic topic = new Topic() { Id = Guid.NewGuid(), Name = name }; topicRepository.Create(topic); return(CreatedAtAction("Get", new { id = topic.Id }, topic)); }
public ActionResult <Topic> Post(string name) { Topic topic = new Topic(name); var resultValidation = new TopicValidator().Validate(topic); if (!resultValidation.IsValid) { return(BadRequest(resultValidation.Errors)); } topicRepository.Create(topic); return(CreatedAtAction("Get", new { id = topic.Id }, topic)); }
public IActionResult Edit(TopicModel model) { var entity = mapper.Map <Topic>(model); var topicFiles = mapper.Map <List <TopicFile> >(model.TopicFiles); Topic newEntity; if (model.Id == 0) { newEntity = topicRepository.Create(entity); } else { newEntity = topicRepository.Update(entity); } topicFileRepository.UpdateFiles(newEntity.Id, topicFiles); return(RedirectToAction("Index")); }
public Topic PostNewTopic(Forum forum, User user, ForumPermissionContext permissionContext, NewPost newPost, string ip, string userUrl, Func <Topic, string> topicLinkGenerator, DateTime timeStamp) { if (!permissionContext.UserCanPost || !permissionContext.UserCanView) { throw new Exception(String.Format("User {0} can't post to forum {1}.", user.Name, forum.Title)); } newPost.Title = _textParsingService.EscapeHtmlAndCensor(newPost.Title); if (newPost.IsPlainText) { newPost.FullText = _textParsingService.ForumCodeToHtml(newPost.FullText); } else { newPost.FullText = _textParsingService.ClientHtmlToHtml(newPost.FullText); } var urlName = newPost.Title.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newPost.Title.ToUrlName())); //var timeStamp = DateTime.UtcNow; var topicID = _topicRepository.Create(forum.ForumID, newPost.Title, 0, 0, user.UserID, user.Name, user.UserID, user.Name, timeStamp, false, false, false, false, urlName); var postID = _postRepository.Create(topicID, 0, ip, true, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, timeStamp, false, user.Name, null, false, 0, newPost.IsAnonymous, newPost.FileUrl); _forumRepository.UpdateLastTimeAndUser(forum.ForumID, timeStamp, user.Name); _forumRepository.IncrementPostAndTopicCount(forum.ForumID); _profileRepository.SetLastPostID(user.UserID, postID); var topic = new Topic(topicID) { ForumID = forum.ForumID, IsClosed = false, IsDeleted = false, IsIndexed = false, IsPinned = false, LastPostName = user.Name, LastPostTime = timeStamp, LastPostUserID = user.UserID, ReplyCount = 0, StartedByName = user.Name, StartedByUserID = user.UserID, Title = newPost.Title, UrlName = urlName, ViewCount = 0 }; // <a href="{0}">{1}</a> started a new topic: <a href="{2}">{3}</a> var topicLink = topicLinkGenerator(topic); var message = String.Format(Resources.NewPostPublishMessage, userUrl, user.Name, topicLink, topic.Title); var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(forum.ForumID).Count > 0; _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewTopic, forumHasViewRestrictions); _eventPublisher.ProcessEvent(String.Empty, user, EventDefinitionService.StaticEventIDs.NewPost, true); forum = _forumRepository.Get(forum.ForumID); _broker.NotifyForumUpdate(forum); _broker.NotifyTopicUpdate(topic, forum, topicLink); return(topic); }
public void Create(Topic topic) { _topicRepository.Create(topic); }
public Topic Create(Topic topic) { return(_topRepo.Create(topic)); }
public bool Create(Topic entity) { return(_topicRepository.Create(entity)); }
public IActionResult Create(Topic topic) { _repository.Create(topic); return(CreatedAtAction(nameof(GetById), new { id = topic.Id }, topic)); }
public async Task <BasicServiceResponse <Topic> > PostNewTopic(User user, NewPost newPost, string ip, string userUrl, Func <Topic, string> topicLinkGenerator, Func <Topic, string> redirectLinkGenerator) { if (user == null) { return(GetPostFailMessage(Resources.LoginToPost)); } var forum = await _forumRepository.Get(newPost.ItemID); if (forum == null) { throw new Exception($"Forum {newPost.ItemID} not found"); } var permissionContext = await _forumPermissionService.GetPermissionContext(forum, user); if (!permissionContext.UserCanView) { return(GetPostFailMessage(Resources.ForumNoView)); } if (!permissionContext.UserCanPost) { return(GetPostFailMessage(Resources.ForumNoPost)); } newPost.FullText = newPost.IsPlainText ? _textParsingService.ForumCodeToHtml(newPost.FullText) : _textParsingService.ClientHtmlToHtml(newPost.FullText); if (await IsNewPostDupeOrInTimeLimit(newPost.FullText, user)) { return(GetPostFailMessage(string.Format(Resources.PostWait, _settingsManager.Current.MinimumSecondsBetweenPosts))); } if (string.IsNullOrWhiteSpace(newPost.FullText) || string.IsNullOrWhiteSpace(newPost.Title)) { return(GetPostFailMessage(Resources.PostEmpty)); } newPost.Title = _textParsingService.Censor(newPost.Title); var urlName = newPost.Title.ToUniqueUrlName(await _topicRepository.GetUrlNamesThatStartWith(newPost.Title.ToUrlName())); var timeStamp = DateTime.UtcNow; var topicID = await _topicRepository.Create(forum.ForumID, newPost.Title, 0, 0, user.UserID, user.Name, user.UserID, user.Name, timeStamp, false, false, false, urlName); var postID = await _postRepository.Create(topicID, 0, ip, true, newPost.IncludeSignature, user.UserID, user.Name, newPost.Title, newPost.FullText, timeStamp, false, user.Name, null, false, 0); await _forumRepository.UpdateLastTimeAndUser(forum.ForumID, timeStamp, user.Name); await _forumRepository.IncrementPostAndTopicCount(forum.ForumID); await _profileRepository.SetLastPostID(user.UserID, postID); var topic = new Topic { TopicID = topicID, ForumID = forum.ForumID, IsClosed = false, IsDeleted = false, IsPinned = false, LastPostName = user.Name, LastPostTime = timeStamp, LastPostUserID = user.UserID, ReplyCount = 0, StartedByName = user.Name, StartedByUserID = user.UserID, Title = newPost.Title, UrlName = urlName, ViewCount = 0 }; // <a href="{0}">{1}</a> started a new topic: <a href="{2}">{3}</a> var topicLink = topicLinkGenerator(topic); var message = string.Format(Resources.NewPostPublishMessage, userUrl, user.Name, topicLink, topic.Title); var forumHasViewRestrictions = _forumRepository.GetForumViewRoles(forum.ForumID).Result.Count > 0; await _eventPublisher.ProcessEvent(message, user, EventDefinitionService.StaticEventIDs.NewTopic, forumHasViewRestrictions); await _eventPublisher.ProcessEvent(string.Empty, user, EventDefinitionService.StaticEventIDs.NewPost, true); forum = await _forumRepository.Get(forum.ForumID); _broker.NotifyForumUpdate(forum); _broker.NotifyTopicUpdate(topic, forum, topicLink); await _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID }); _topicViewCountService.SetViewedTopic(topic); var redirectLink = redirectLinkGenerator(topic); return(new BasicServiceResponse <Topic> { Data = topic, Message = null, Redirect = redirectLink, IsSuccessful = true }); }
public async Task <Topic> CreateTopic(string topicName) { var topic = new Topic(topicName); return(await _topicRepository.Create(topic)); }
public Topic Create(Topic topic) { _topicValidator.DefaultValidation(topic); return(_topRepo.Create(topic)); }