aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.DAL.Observables/Partials/User.cs
blob: 805c389fcf36e206b050134b6ea73d3213917fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.DAL.Observables
{
    public partial class User
    {
        /// <summary>
        /// Determines whether the user has the specified permission.
        /// </summary>
        /// <param name="permission">The permission.</param>
        /// <returns>
        ///   <c>true</c> if the user has permission; otherwise, <c>false</c>.
        /// </returns>
        public bool HasPermission(Permissions permission)
        {
            return UsersRoles.Select(x => x.Role).ToList().SelectMany(x => x.RolesPermissions).ToList().Exists(x => x.Permission.Code == permission.ToInt32());
        }

        /// <summary>
        /// Gets the aggregated user permissions.
        /// </summary>
        public List<Permissions> GetPermissions()
        {
            return UsersRoles.Select(x => x.Role).ToList().SelectMany(x => x.RolesPermissions).Select(x => (Permissions)x.Permission.Code).ToList();
        }

        /// <summary>
        /// Gets the aggregated user roles.
        /// </summary>
        public List<Roles> GetRoles()
        {
            return UsersRoles.Select(x => (Roles)x.Role.Code).ToList();
        }
    }
}