no comment
This commit is contained in:
@ -12,7 +12,7 @@ using Yavsc.Models;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Yavsc.ViewModels.Blogspot;
|
||||
|
||||
using Yavsc.Models.Blog;
|
||||
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
@ -46,9 +46,11 @@ namespace Yavsc.Controllers
|
||||
string uid = User.GetUserId();
|
||||
long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid))
|
||||
.Select(c=>c.Id).ToArray();
|
||||
IQueryable<Blog> posts ;
|
||||
IQueryable<BlogPost> posts ;
|
||||
if (usercircles != null) {
|
||||
posts = _context.Blogspot.Include(b => b.Author)
|
||||
.Include(p=>p.Tags)
|
||||
.Include(p=>p.Comments)
|
||||
.Include(p=>p.ACL)
|
||||
.Where(p=> p.AuthorId == uid || p.Visible &&
|
||||
(p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))))
|
||||
@ -104,10 +106,11 @@ namespace Yavsc.Controllers
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Blog blog = _context.Blogspot.Include(
|
||||
BlogPost blog = _context.Blogspot.Include(
|
||||
b => b.Author
|
||||
)
|
||||
.Include(p=>p.Tags)
|
||||
.Include(p=>p.Comments)
|
||||
.Include(p => p.ACL).Single(m => m.Id == id);
|
||||
if (blog == null)
|
||||
{
|
||||
@ -117,6 +120,7 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
ViewData["apicmtctlr"] = "/api/blogcomments";
|
||||
return View(blog);
|
||||
}
|
||||
|
||||
@ -124,14 +128,14 @@ namespace Yavsc.Controllers
|
||||
[Authorize()]
|
||||
public IActionResult Create(string title)
|
||||
{
|
||||
var result = new Blog{Title=title};
|
||||
var result = new BlogPost{Title=title};
|
||||
ViewData["PostTarget"]="Create";
|
||||
return View("Edit",result);
|
||||
}
|
||||
|
||||
// POST: Blog/Create
|
||||
[HttpPost, Authorize, ValidateAntiForgeryToken]
|
||||
public IActionResult Create(Blog blog)
|
||||
public IActionResult Create(Models.Blog.BlogPost blog)
|
||||
{
|
||||
blog.Rate = 0;
|
||||
blog.AuthorId = User.GetUserId();
|
||||
@ -157,7 +161,7 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
|
||||
ViewData["PostTarget"]="Edit";
|
||||
Blog blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
||||
BlogPost blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
||||
|
||||
|
||||
if (blog == null)
|
||||
@ -187,7 +191,7 @@ namespace Yavsc.Controllers
|
||||
// POST: Blog/Edit/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken,Authorize()]
|
||||
public IActionResult Edit(Blog blog)
|
||||
public IActionResult Edit(BlogPost blog)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
@ -219,7 +223,7 @@ namespace Yavsc.Controllers
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Blog blog = _context.Blogspot.Include(
|
||||
BlogPost blog = _context.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Single(m => m.Id == id);
|
||||
if (blog == null)
|
||||
@ -235,7 +239,7 @@ namespace Yavsc.Controllers
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult DeleteConfirmed(long id)
|
||||
{
|
||||
Blog blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement());
|
||||
if (auth.Result)
|
||||
{
|
||||
|
129
Yavsc/Controllers/CommentsController.cs
Normal file
129
Yavsc/Controllers/CommentsController.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
public class CommentsController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public CommentsController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: Comments
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var applicationDbContext = _context.Comment.Include(c => c.Post);
|
||||
return View(await applicationDbContext.ToListAsync());
|
||||
}
|
||||
|
||||
// GET: Comments/Details/5
|
||||
public async Task<IActionResult> Details(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
if (comment == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
// GET: Comments/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post");
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Comments/Create
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Create(Comment comment)
|
||||
{
|
||||
comment.UserCreated = User.GetUserId();
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_context.Comment.Add(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
// GET: Comments/Edit/5
|
||||
public async Task<IActionResult> Edit(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
if (comment == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
// POST: Comments/Edit/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Edit(Comment comment)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_context.Update(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
// GET: Comments/Delete/5
|
||||
[ActionName("Delete")]
|
||||
public async Task<IActionResult> Delete(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
if (comment == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
// POST: Comments/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(long id)
|
||||
{
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
_context.Comment.Remove(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user