aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/Enumerations/JobStatuses.cs
blob: 546ecca6775c7580a2345116cdd245d75114b2d2 (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.BL.Enumerations
{
    public enum JobStatuses
    {
        //Draft
        [Description("Draft")]
        Draft,

        //Completed
        [Description("Completed")]
        Completed,

        //Disrupted
        [Description("Disrupted")]
        Disrupted,
    }
}
round-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Enumerations;
using SimpleValidator.Extensions;
using Newtonsoft.Json;
using System.Xml.Serialization;
using Tango.Core.Cryptography;

namespace Tango.BL.Entities
{
    public partial class User : UserBase
    {
        private static IHashGenerator _hashGenerator;

        /// <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>
        /// Determines whether the user has role.
        /// </summary>
        /// <param name="role">The role.</param>
        public bool HasRole(Roles role)
        {
            return UsersRoles.ToList().Exists(x => x.Role.Code == role.ToInt32());
        }

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

        /// <summary>
        /// Gets the aggregated FSE user roles.
        /// </summary>
        [NotMapped]
        public List<Role> FSERoles
        {
            get { return UsersRoles.Select(x => x.Role).Where(x => x.Name.StartsWith("FSE")).ToList(); }
        }

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

        protected override void RaisePropertyChanged(string propName)
        {
            base.RaisePropertyChanged(propName);
        }

        public override bool Validate(ObservablesContext context)
        {
            return base.Validate(context) && Contact.Validate(context) && Address.Validate(context);
        }

        protected override void OnValidating(ObservablesContext context)
        {
            base.OnValidating(context);

            var users = context.Users.ToList();

            if (users.Exists(x => x.Guid != Guid && x.Email.ToLower() == Email.ToLower()))
            {
                InsertError(nameof(Email), "The specified email is already taken by another account.");
            }

            if (!Email.IsEmail())
            {
                InsertError(nameof(Email), "The specified email address is invalid.");
            }
        }

        /// <summary>
        /// Gets the specified password hash.
        /// </summary>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public static String GetPasswordHash(String password)
        {
            return GetHashGenerator().Encrypt(password);
        }

        private static IHashGenerator GetHashGenerator()
        {
            if (_hashGenerator == null)
            {
                _hashGenerator = new BasicHashGenerator();
            }

            return _hashGenerator;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="User" /> class.
        /// </summary>
        public User() : base()
        {

        }
    }
}