Exemplo n.º 1
0
        public async Task <IActionResult> Story(int year, int month, int day, string slug)
        {
            var fullSlug = $"{year}/{month}/{day}/{slug}";

            try
            {
                var story = await _repo.GetStory(fullSlug);

                // Try with other slug if it doesn't work
                if (story == null)
                {
                    story = await _repo.GetStory($"{year:0000}/{month:00}/{day:00}/{slug}");
                }

                if (story != null)
                {
                    FixSyntaxes(story);
                    return(View(story));
                }
            }
            catch
            {
                _logger.LogWarning($"Couldn't find the ${fullSlug} story");
            }

            return(Redirect("/"));
        }
Exemplo n.º 2
0
        public async Task <bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
        {
            await EnsureUser(username, password);

            if (post.categories == null)
            {
                throw new MetaWeblogException("Failed to specify categories");
            }

            try
            {
                var story = await _repo.GetStory(int.Parse(postid));

                story.Title = post.title;
                story.Body  = post.description;
                if (post.dateCreated == DateTime.MinValue)
                {
                    story.DatePublished = DateTime.UtcNow;                                // Only overwrite date if is empty
                }
                story.Categories  = string.Join(",", post.categories);
                story.IsPublished = publish;
                if (string.IsNullOrWhiteSpace(story.Slug))
                {
                    story.Slug = story.GetStoryUrl();                                // Only recalcuate Slug if absolutely necessary
                }
                story.FeatureImageUrl = post.wp_post_thumbnail;
                story.Abstract        = story.GetSummary();

                if (await _repo.SaveAllAsync())
                {
                    return(true);
                }
            }
            catch (Exception)
            {
                _logger.LogError("Failed to edit the post.");
            }

            throw new MetaWeblogException("Failed to edit the post.");
        }