RoleController.cs 1.02 KB
Newer Older
Marcel Nellesen's avatar
Marcel Nellesen committed
1
2
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
3
using Microsoft.AspNetCore.Authorization;
4
using Microsoft.AspNetCore.Mvc;
5
using System.Collections.Generic;
6
7
8
9
using System.Linq;

namespace Coscine.Api.Project.Controllers
{
10
11
12
13

    /// <summary>
    /// This controller represents the actions which can be taken with a role object
    /// </summary>
14
    [Authorize]
15
16
17
18
    public class RoleController : Controller
    {
        private readonly RoleModel _roleModel;

19
20
21
        /// <summary>
        /// RoleController specifying a RoleModel
        /// </summary>
22
23
24
25
26
        public RoleController()
        {
            _roleModel = new RoleModel();
        }

27
28
29
30
        /// <summary>
        /// Returns all available roles
        /// </summary>
        /// <returns>All Roles </returns>
31
        [Route("[controller]")]
32
        public ActionResult<IEnumerable<RoleObject>> Index()
33
        {
34
35
            return Json(_roleModel.GetAll()
                .Select((role) => new RoleObject(role.Id, role.DisplayName)));
36
37
38
        }
    }
}