2
\$\begingroup\$

The 3 methods below all need to have the same name: "Roles"

They need to be the same as I have a permissions system that will only allow the execution of a "Roles" method.

I don't feel too happy about the third method because in order to keep the compiler happy, I have to declare a pointless and never used string variable.

Can anyone think of a better way of doing this?

public partial class PartialsController
{
    [Route("roles")]
    public async Task<ActionResult> Roles()
    {
        ViewBag.InitialData = await Uow.Roles.Query(InitialQuery("name", "asc"));
        return PartialView("Roles/ListRoles");
    }

    [Route("roles/{id:guid}")]
    public async Task<ActionResult> Roles(Guid id)
    {
        ViewBag.Role = await Uow.Roles.GetById(id);
        ViewBag.Permissions = await Uow.Permissions.GetAll().Select(p => new { p.Id, p.Description }).ToListAsync();
        return PartialView("Roles/EditRole");
    }

    [Route("roles/new")]
    public async Task<ActionResult> Roles(string nothing)
    {
        ViewBag.Permissions = await Uow.Permissions.GetAll().Select(p => new { p.Id, p.Description }).ToListAsync();
        return PartialView("Roles/EditRole");
    }
}
\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.