public async Task <IActionResult> Create(string blogname, [Bind("Id,Title,Published,content,Author,RowVersion,BlogId,engine,CategoriesToString")] ViewPost post) { //if (ModelState.IsValid) { post.Author = await PostManager.db.Users.FirstAsync(x => x.UserName == User.Identity.Name); var mpost = post.ToModel(User.Identity.Name); MarkUpManager markDownManager = new MarkUpManager(); mpost.content = markDownManager.ConvertFromHtmlToMarkUp(post.content); var blog = await blmngr.GetBlogByIdAsync(mpost.BlogId); await postManager.Create(mpost, this.User.Identity.Name); if (post.CategoriesToString != null) { var catgories = post.CategoriesToString.Split(",").ToList(); if (catgories != null) { await CategoryManager.AttachCategoryRangetoPost(catgories, blog.Name, mpost.Id); } } if (post.TagsToString != null) { var tags = post.TagsToString.Split(",").ToList(); if (tags != null) { await TagManager.AttachTagRangetoPost(tags, blog.Name, mpost.Id); } } //blmngr.GetBlogAsync() return(RedirectToAction(nameof(Index), "Posts", new { id = blog.Name })); } // return View(post); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Published,content,Author,RowVersion,BlogId,engine")] ViewPost post, string blogname) { try { if (id != post.Id) { return(NotFound()); } // if (ModelState.IsValid) // { //_context.Update(post); //await _context.SaveChangesAsync(); var mpost = post.ToModel(User.Identity.Name); MarkUpManager markDownManager = new MarkUpManager(); mpost.content = markDownManager.ConvertFromHtmlToMarkUp(post.content); mpost = await postManager.Edit(id, mpost); var blog = await blmngr.GetBlogByIdAsync(mpost.BlogId); if (mpost != null) { post.ImportFromModel(mpost); } if (post.CategoriesToString != null) { var catgories = post.CategoriesToString.Split(",").ToList(); if (catgories != null) { CategoryManager.DettachCategoryRangetoPost(catgories, blog.Name, mpost.Id); CategoryManager.AttachCategoryRangetoPost(catgories, blog.Name, mpost.Id); } } if (post.TagsToString != null) { var tags = post.TagsToString.Split(",").ToList(); if (tags != null) { TagManager.DettachTagRangetoPost(tags, blog.Name, mpost.Id); TagManager.AttachTagRangetoPost(tags, blog.Name, mpost.Id); } } // } } catch (DbUpdateConcurrencyException) { if (this.postManager.Exists(post.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), "Posts", new { id = post.Blog.Name })); //return View(post); }