Lock or release a controller according to some condition

4

I have a controller that should only be accessed if an attribute in my table is "true". Is there any way the user can click on that link, check if the attribute is true, and then release the access?

    
asked by anonymous 19.10.2014 / 04:37

1 answer

4

You can let the user access the Controller without problems. Just create a business rule that does not allow you to continue:

public ActionResult AdicionarCapitulos(int id)
{
    var publicacao = contexto.Publicacoes.SingleOrDefault(p => p.Id == id);
    if (!publicacao.Validada) 
    {
        ModelState.AddModelError("", "Publicação ainda não validada. Não é permitido a edição.");
        return RedirectToAction("Index", "Publicacoes");
    }

    // Coloque aqui o resto da lógica
}
    
19.10.2014 / 19:26