Esempio n. 1
0
        public TUser Create(string identity, string @namespace, string password, UserStatus status = UserStatus.Active, string description = null)
        {
            if (string.IsNullOrWhiteSpace(identity))
            {
                throw new ArgumentNullException(nameof(identity));
            }

            var user = this.CreateUser(null);

            user.Namespace   = @namespace;
            user.Status      = status;
            user.Description = string.IsNullOrEmpty(description) ? null : description;

            switch (MembershipUtility.GetIdentityType(identity))
            {
            case UserIdentityType.Name:
                user.Name = identity;
                break;

            case UserIdentityType.Phone:
                user.Phone = identity;
                break;

            case UserIdentityType.Email:
                user.Email = identity;
                break;
            }

            return(this.Create(user, password) ? user : default);
Esempio n. 2
0
        public bool Exists(string identity, string @namespace = null)
        {
            if (string.IsNullOrWhiteSpace(identity))
            {
                return(false);
            }

            return(this.DataAccess.Exists <TUser>(MembershipUtility.GetIdentityCondition(identity) & this.GetNamespace(@namespace)));
        }
Esempio n. 3
0
        public IEnumerable <TRole> GetAncestors(uint memberId, MemberType memberType)
        {
            switch (memberType)
            {
            case MemberType.User:
                var user = this.DataAccess.Select <TUser>(Condition.Equal(nameof(IUser.UserId), memberId)).FirstOrDefault();
                return(user == null ? null : MembershipUtility.GetAncestors <TRole>(this.DataAccess, user));

            case MemberType.Role:
                var role = this.DataAccess.Select <TRole>(Condition.Equal(nameof(IRole.RoleId), memberId)).FirstOrDefault();
                return(role == null ? null : MembershipUtility.GetAncestors <TRole>(this.DataAccess, role));

            default:
                return(null);
            }
        }
Esempio n. 4
0
 public TUser GetUser(string identity, string @namespace = null)
 {
     EnsureRoles();
     return(this.DataAccess.Select <TUser>(MembershipUtility.GetIdentityCondition(identity) & this.GetNamespace(@namespace)).FirstOrDefault());
 }