There is an Index method, a NewsController controller. It shows a View with a collection of news.
Moreover, if it was a Request from the User’s account, then the news that this user created and no matter what his role is shown, it’s only important that this request was made from the User’s account. If Request is made from the Administrator's Cabinet, on the same Index method, then it shows the news of all users and renders the same View , but with enhanced functionality, and then the roles already come into play. If admin , then add. buttons.
Question: how best to do it?
I have several options, but I don’t know which one to choose:
Based on Routes:
routes.MapRoute( name: "Admin News", url: "Admin/News", defaults: new { controller = "News", action = "Index" } ); routes.MapRoute( name: "Profile News", url: "Profile/News", defaults: new { controller = "News", action = "Index" } );
Accordingly, already in the controller's method to check with which URL Request was made from, and building on this data, to tune the View functionality.
Pass an additional parameter to the
Indexmethod of theNewscontroller:public ActionResult Index(bool IsAdminCabinet, ... ) { ... }Or add two more methods:
Newsin theProfileandAdmincontrollers:public class ProfileController : Controller { public ActionResult News() { return RedirectToAction("Index", "News"); } } public class AdminController : Controller { public ActionResult News() { TempData["IsAdminCabinet"] = true; return RedirectToAction("Index", "News"); } }