Exemplo n.º 1
0
		public IActionResult New() {
			var x = RouteData.Values;
			ViewData["Title"] = "New blog";
			ViewData["IsAuthed"] = IsAuthed();
			var model = new BlogEntry();
			return View("Edit", model);
		}
Exemplo n.º 2
0
		public IActionResult Preview(string title, string slug, string markdownContent) {
			return ApiResponse(() => {
				if (!IsAuthed()) return NotAuthedApiResponse();
				ViewData["IsAuthed"] = true;
				var now = DateTimeOffset.Now;
				var model = new BlogEntry {
					MarkdownContent = markdownContent,
					HtmlContent = CommonMark.CommonMarkConverter.Convert(markdownContent),
					Title = title,
					Slug = slug,
					DateCreated = now,
					DateLastModified = now,
					DatePublished = now
				};
				return RenderPartialViewToString("_BlogEntry", model);
			});
		}
Exemplo n.º 3
0
		public IActionResult Save(Guid entryId, string title, string slug, string markdownContent) {
			return ApiResponse(() => {
				if (!IsAuthed()) return NotAuthedApiResponse();

				var htmlContent = CommonMark.CommonMarkConverter.Convert(markdownContent);
				var now = DateTimeOffset.Now;

				BlogEntry model;
				if (entryId == Guid.Empty) {
					model = new BlogEntry {
						MarkdownContent = markdownContent,
						HtmlContent = htmlContent,
						Title = title,
						Slug = slug,
						DateCreated = now,
						DateLastModified = now,
						DatePublished = now
					};
				} else {
					// TODO: Handle lookup failure
					model = _blogService.GetById(entryId);
					model.MarkdownContent = markdownContent;
					model.HtmlContent = htmlContent;
					model.Title = title;
					model.Slug = slug;
					model.DateLastModified = now;
				}

				_blogService.SaveBlogEntry(model);

				return new { RedirectUrl = model.Url };
			});
		}