public async Task <string> NewPost( string blogId, string userName, string password, PostStruct newPost, bool publish, string authorDisplayName ) { var post = mapper.GetPostFromStruct(newPost); post.BlogId = blogId; post.Id = Guid.NewGuid().ToString(); post.Author = authorDisplayName; post.IsPublished = publish; //TODO: resolve timezone for pubdate? //post.PubDate = post.PubDate.AddHours(-6); await blogService.Create( blogId, userName, password, post, publish ).ConfigureAwait(false); return(post.Id); }
public async Task <string> NewPost( string blogId, string userName, string password, PostStruct newPost, bool publish, string authorDisplayName ) { var permission = await _security.ValidatePermissions( blogId, userName, password, CancellationToken.None ).ConfigureAwait(false); if (!permission.CanEditPosts) { _log.LogWarning($"rejecting new post because user {userName} cannot edit posts"); return(null); } var post = _mapper.GetPostFromStruct(newPost); post.BlogId = blogId; post.Id = Guid.NewGuid().ToString(); post.Author = authorDisplayName; post.CreatedByUser = permission.DisplayName; if (publish) { post.IsPublished = true; if (post.IsPublished) { post.PubDate = DateTime.UtcNow; } } else { post.DraftAuthor = post.Author; post.DraftContent = post.Content; post.Content = null; post.PubDate = null; } var convertToRelativeUrls = true; await _blogService.Create(post, convertToRelativeUrls).ConfigureAwait(false); if (publish) { await _blogService.FirePublishEvent(post); } return(post.Id); }
public async Task <string> NewPost( string blogId, string userName, string password, PostStruct newPost, bool publish, string authorDisplayName ) { var permission = await _security.ValidatePermissions( blogId, userName, password, CancellationToken.None ).ConfigureAwait(false); if (!permission.CanEditPosts) { _log.LogWarning($"rejecting new post because user {userName} cannot edit posts"); return(null); } var post = _mapper.GetPostFromStruct(newPost); post.BlogId = blogId; post.Id = Guid.NewGuid().ToString(); post.Author = authorDisplayName; post.CreatedByUser = permission.DisplayName; var utcPubDate = _timeZoneHelper.ConvertToUtc(newPost.postDate, permission.TimeZoneId); if (publish) { if (utcPubDate.Year == 1) { //invalid because not supplied utcPubDate = DateTime.UtcNow; } if (utcPubDate <= DateTime.UtcNow) { post.IsPublished = true; post.PubDate = utcPubDate; } else { //future date needs to be draft, it will auto publish after pub date post.DraftAuthor = post.Author; post.DraftContent = post.Content; post.DraftPubDate = utcPubDate; post.IsPublished = false; post.PubDate = null; post.Content = null; } } else { post.DraftAuthor = post.Author; post.DraftContent = post.Content; if (utcPubDate > DateTime.UtcNow) { post.DraftPubDate = utcPubDate; } post.Content = null; post.PubDate = null; } await _blogUrlResolver.ConvertMediaToRelativeUrls(post).ConfigureAwait(false); await _blogService.Create(post).ConfigureAwait(false); if (publish) { await _blogService.FirePublishEvent(post).ConfigureAwait(false); } return(post.Id); }