Пример #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("/"));
        }
Пример #2
0
        public bool EditPost(string postid, string username, string password, Post post, bool publish)
        {
            EnsureUser(username, password).Wait();

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

            try
            {
                var story = _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
                }
                _repo.SaveAll();

                return(true);
            }
            catch (Exception)
            {
                throw new MetaWeblogException("Failed to edit the post.");
            }
        }
Пример #3
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 = _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

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

      throw new MetaWeblogException("Failed to edit the post.");
    }
Пример #4
0
        public bool EditPost(string postid, string username, string password, Post post, bool publish)
        {
            EnsureUser(username, password).Wait();

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

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

                story.Title         = post.title;
                story.Body          = post.description;
                story.DatePublished = post.dateCreated == DateTime.MinValue ? DateTime.UtcNow : post.dateCreated;
                story.Categories    = string.Join(",", post.categories);
                story.IsPublished   = publish;
                story.Slug          = story.GetStoryUrl();

                _repo.SaveAll();

                return(true);
            }
            catch (Exception)
            {
                throw new MetaWeblogException("Failed to edit the post.");
            }
        }
Пример #5
0
        public IActionResult Story(int year, int month, int day, string slug)
        {
            var fullSlug = $"{year}/{month}/{day}/{slug}";

            var story = _repo.GetStory(fullSlug);

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

            if (story == null)
            {
                return(Redirect("/"));
            }

            return(View(story));
        }