Last active
May 17, 2018 08:06
-
-
Save danielplawgo/71903ccde316b38103947de0df498d2b to your computer and use it in GitHub Desktop.
Własny filtr akcji – autoryzacja z wykorzystaniem logiki biznesowej
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool HasAccess(ApplicationUser user, Invoice entity) | |
{ | |
if(user == null) | |
{ | |
throw new ArgumentNullException("user"); | |
} | |
if(entity == null) | |
{ | |
throw new ArgumentNullException("entity"); | |
} | |
if(entity.UserId == user.Id) | |
{ | |
return true; | |
} | |
if (user.IsAdmin) | |
{ | |
return true; | |
} | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InvoicesController : Controller | |
{ | |
public ActionResult Create(int id) | |
{ | |
return View(); | |
} | |
public ActionResult Edit(int id) | |
{ | |
return View(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[LogicAuthorize(typeof(IInvoiceLogic))] | |
public class InvoicesController : Controller | |
{ | |
private IInvoiceLogic _invoiceLogic; | |
public InvoicesController(IInvoiceLogic invoiceLogic) | |
{ | |
_invoiceLogic = invoiceLogic; | |
} | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
public ActionResult Edit(int id) | |
{ | |
return View(_invoiceLogic.GetById(id)); | |
} | |
[HttpPost] | |
public ActionResult Edit(Invoice invoice) | |
{ | |
return View(invoice); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment