aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Observables/Partials/User.cs
blob: b70aae8a43222711b446bfd56c5f30e703f7c15f (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.Integration.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 roles as enumerations.
        /// </summary>
        public List<Roles> Roles
        {
            get { return UsersRoles.Select(x => (Roles)x.Role.Code).ToList(); }
        }

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