I am working on ASP.NET (MVC3 HTML5) web site. I need somehow to allow admin to edit content like news, homepage text, promotions etc. Can i implement this using existing API?
Thank you.
I am working on ASP.NET (MVC3 HTML5) web site. I need somehow to allow admin to edit content like news, homepage text, promotions etc. Can i implement this using existing API?
Thank you.
Very simple. Make an interface for editing the content you want the admin to edit and protect it with the [Authorize] attribute
//for the users
[Authorize]
public ActionResult NormalUsers(int newsItemId)
{
//Getting content from DB.
NewsItem news = new NewsItem(newsItemId);
return View("ShowNews", news);
}
//for editors
[Authorize(Roles = "Admin, Super User")]
[HttpGet]
public ActionResult AdministratorsOnly(int newsItemId)
{
//Getting content from DB
NewsItem news = new NewsItem(newsItemId);
return View("EditNews", news);
}
[Authorize(Roles = "Admin, Super User")]
[HttpPost]
public ActionResult AdministratorsOnly(NewsItem newsItem)
{
//Putting content in DB
newsRepository.StoreNewsItemInDB(newsItem);
NewsItem news = new NewsItem(newsItem.Id);//getting the newsItem from DB, to allow for server side processing.
return View("EditNews", news);
}
Link to MSDN for the language details.
The way it could work is that you have two(actually three) views for news. The first view is for presenting the NewsItem-object for the common user.
The second views are for getting the NewsItem-object for editing. And the third view is for showing the NewsItem-object after editing, to ensure the end result of the editing.
The users will always be presented with the last edited NewsItem(the same as 3).