factorize creation and edition views
This commit is contained in:
@ -123,25 +123,27 @@ namespace Yavsc.Controllers
|
|||||||
public IActionResult Create(string title)
|
public IActionResult Create(string title)
|
||||||
{
|
{
|
||||||
var result = new Blog{Title=title};
|
var result = new Blog{Title=title};
|
||||||
return View(result);
|
ViewData["PostTarget"]="Create";
|
||||||
|
return View("Edit",result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: Blog/Create
|
// POST: Blog/Create
|
||||||
[HttpPost, Authorize(), ValidateAntiForgeryToken]
|
[HttpPost, Authorize, ValidateAntiForgeryToken]
|
||||||
public IActionResult Create(Blog blog)
|
public IActionResult Create(Blog blog)
|
||||||
{
|
{
|
||||||
blog.Rate = 0;
|
blog.Rate = 0;
|
||||||
blog.AuthorId = User.GetUserId();
|
blog.AuthorId = User.GetUserId();
|
||||||
ModelState.ClearValidationState("AuthorId");
|
|
||||||
blog.Id=0;
|
blog.Id=0;
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
||||||
_context.Blogspot.Add(blog);
|
_context.Blogspot.Add(blog);
|
||||||
_context.SaveChanges(User.GetUserId());
|
_context.SaveChanges(User.GetUserId());
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
ModelState.AddModelError("Unknown","Invalid Blog posted ...");
|
ModelState.AddModelError("Unknown","Invalid Blog posted ...");
|
||||||
return View(blog);
|
ViewData["PostTarget"]="Create";
|
||||||
|
return View("Edit",blog);
|
||||||
}
|
}
|
||||||
[Authorize()]
|
[Authorize()]
|
||||||
// GET: Blog/Edit/5
|
// GET: Blog/Edit/5
|
||||||
@ -152,6 +154,7 @@ namespace Yavsc.Controllers
|
|||||||
return HttpNotFound();
|
return HttpNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewData["PostTarget"]="Edit";
|
||||||
Blog blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
Blog blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
||||||
|
|
||||||
|
|
||||||
@ -201,6 +204,7 @@ namespace Yavsc.Controllers
|
|||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ViewData["PostTarget"]="Edit";
|
||||||
return View(blog);
|
return View(blog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace Yavsc.Models
|
|||||||
|
|
||||||
public bool AuthorizeCircle(long circleId)
|
public bool AuthorizeCircle(long circleId)
|
||||||
{
|
{
|
||||||
return ACL.Any( i=>i.CircleId == circleId);
|
return ACL?.Any( i=>i.CircleId == circleId) ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetOwnerId()
|
public string GetOwnerId()
|
||||||
|
Reference in New Issue
Block a user