public ActionResult Create() { var articleform = new FullArticleViewModel(); articleform.User = _userService.GetUserByNickname(User.Identity.Name)?.ToMvcUser(); return(View(articleform)); }
public ActionResult Delete(FullArticleViewModel fullArticle, int blogId, int userId) { fullArticle.User = _userService.GetUserEntity(userId)?.ToMvcUser(); fullArticle.Blog = _blogService.GetSimpleBlogById(blogId)?.ToMvcSimpleBlog(); _articleService.DeleteArticle(fullArticle.ToBllFullArticle()); return(RedirectToAction("Index")); }
public ActionResult FullArticleBySlug(string slug) { if (string.IsNullOrWhiteSpace(slug)) { return(RedirectToAction(nameof(BlogPostController.Index))); } var userId = User.Identity.GetUserId(); var post = DbContext.BlogPosts.FirstOrDefault(p => p.Slug.ToString() == slug); if (post == null) { return(RedirectToAction(nameof(BlogPostController.Index))); } var model = new FullArticleViewModel { ID = post.ID, Title = post.Title, Body = post.Body, MediaUrl = post.MediaUrl }; return(View("FullArticle", model)); }
public static FullArticleEntity ToBllFullArticle(this FullArticleViewModel article) { return new FullArticleEntity() { Id = article.Id, Title = article.Title, CreationTime = article.CreationTime, Text = article.Text, User = article.User.ToBllUser(), TitleImage = article.TitleImage, Blog = article.Blog?.ToBllSimpleBlog(), Tags = article.Tags?.Select(x => x.ToBllSimpleTag()) }; }
public ActionResult Create(FullArticleViewModel articleViewModel, int[] Tags, HttpPostedFileBase PictureInput, int BlogId = 0) { if (ModelState.IsValidField("Text") && ModelState.IsValidField("Title")) { if (BlogId == 0 || Tags == null) { return(RedirectToAction("Create")); } articleViewModel.CreationTime = DateTime.Now; articleViewModel.Tags = Tags.Select(x => _tagService.GetTagEntity(x)?.ToMvcSimpleTag()); articleViewModel.User = _userService.GetUserByNickname(User.Identity.Name)?.ToMvcUser(); articleViewModel.Blog = _blogService.GetSimpleBlogById(BlogId).ToMvcSimpleBlog(); var str = new StringBuilder(); if (PictureInput != null) { str.Append(ImageHelper.SaveTitleImgToDisk(PictureInput, Server.MapPath("~/"))); } articleViewModel.TitleImage = "/ArticlesContent/" + str; _articleService.CreateFullArticleEntity(articleViewModel.ToBllFullArticle()); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); }