コード例 #1
0
        public string blogger_newPost(string appKey, string blogid, string username, string password, string content, bool publish)
        {
            VerifyAccess(username, password);

            var newPost = new Entry();

            newPost.Initialize();
            FillEntryFromBloggerPost(newPost, content, username);
            newPost.IsPublic   = publish;
            newPost.Syndicated = publish;

            newPost.CreatedUtc = newPost.ModifiedUtc = dasBlogSettings.GetCreateTime(newPost.CreatedUtc);

            dataService.SaveEntry(newPost);

            return(newPost.EntryId);
        }
コード例 #2
0
        public IActionResult CreatePost(PostViewModel post, string submit)
        {
            NBR.Entry entry = null;

            modelViewCreator.AddAllLanguages(post);
            if (submit == Constants.BlogPostAddCategoryAction)
            {
                return(HandleNewCategory(post));
            }

            if (submit == Constants.UploadImageAction)
            {
                return(HandleImageUpload(post));
            }

            ValidatePostName(post);
            if (!ModelState.IsValid)
            {
                return(View(post));
            }
            if (!string.IsNullOrWhiteSpace(post.NewCategory))
            {
                ModelState.AddModelError(nameof(post.NewCategory),
                                         $"Please click 'Add' to add the category, \"{post.NewCategory}\" or clear the text before continuing");
                return(View(post));
            }

            try
            {
                entry = mapper.Map <NBR.Entry>(post);

                entry.Initialize();
                entry.Author     = httpContextAccessor.HttpContext.User.Identity.Name;
                entry.Language   = post.Language;
                entry.Latitude   = null;
                entry.Longitude  = null;
                entry.CreatedUtc = entry.ModifiedUtc = dasBlogSettings.GetCreateTime(post.CreatedDateTime);

                var sts = blogManager.CreateEntry(entry);
                if (sts != NBR.EntrySaveState.Added)
                {
                    post.EntryId = entry.EntryId;
                    ModelState.AddModelError("", "Failed to create blog post. Please check Logs for more details.");
                    return(View(post));
                }
            }
            catch (Exception ex)
            {
                logger.LogError(new EventDataItem(EventCodes.Error, null, "Blog post create failed: {0}", ex.Message));
                ModelState.AddModelError("", "Failed to edit blog post. Please check Logs for more details.");
            }

            if (entry != null)
            {
                logger.LogInformation(new EventDataItem(EventCodes.EntryAdded, null, "Blog post created: {0}", entry.Title));
            }

            BreakSiteCache();

            return(View("views/blogpost/editPost.cshtml", post));
        }