Dynamic User Roles

This commit is contained in:
Shaun Walker
2019-08-20 16:43:35 -04:00
parent de4fa48a29
commit 42c6efbfdb
51 changed files with 942 additions and 193 deletions

View File

@ -0,0 +1,68 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Oqtane.Repository;
using Oqtane.Models;
namespace Oqtane.Controllers
{
[Route("{site}/api/[controller]")]
public class RoleController : Controller
{
private readonly IRoleRepository Roles;
public RoleController(IRoleRepository Roles)
{
this.Roles = Roles;
}
// GET: api/<controller>?siteid=x
[HttpGet]
public IEnumerable<Role> Get(string siteid)
{
if (siteid == "")
{
return Roles.GetRoles();
}
else
{
return Roles.GetRoles(int.Parse(siteid));
}
}
// GET api/<controller>/5
[HttpGet("{id}")]
public Role Get(int id)
{
return Roles.GetRole(id);
}
// POST api/<controller>
[HttpPost]
public Role Post([FromBody] Role Role)
{
if (ModelState.IsValid)
{
Role = Roles.AddRole(Role);
}
return Role;
}
// PUT api/<controller>/5
[HttpPut("{id}")]
public Role Put(int id, [FromBody] Role Role)
{
if (ModelState.IsValid)
{
Role = Roles.UpdateRole(Role);
}
return Role;
}
// DELETE api/<controller>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
Roles.DeleteRole(id);
}
}
}