示例#1
0
        public IEnumerable <DalUser> GetByRole(DalRole role)
        {
            if (context.Database.Connection.State != ConnectionState.Open)
            {
                context.Database.Connection.Open();
            }
            Roles r = context.Set <Roles>().FirstOrDefault(roles => roles.id == role.Id);
            IEnumerable <Users> users  = context.Set <Users>().Where(user => user.Roles.Contains(r)).AsEnumerable();
            List <DalUser>      result = new List <DalUser>();

            foreach (Users u in users)
            {
                result.Add(new DalUser()
                {
                    Id           = u.id,
                    Login        = u.Login,
                    Email        = u.Email,
                    FirstName    = u.FirstName,
                    SecondName   = u.SecondName,
                    ThirdName    = u.ThirdName,
                    PasswordHash = u.PasswordHash
                });
            }
            return(result);
        }
示例#2
0
 public static Role ToOrmRole(this DalRole dalRole)
 {
     return(new Role()
     {
         Id = dalRole.Id
     });
 }
        public void Update(DalRole e)
        {
            var role = _context.Set <Role>().Single(u => u.Id == e.Id);

            role.UserRoleName          = e.UserRoleName;
            _context.Entry(role).State = EntityState.Modified;
        }
        public void Delete(DalRole role)
        {
            var delRole = context.Set <Role>()
                          .Single(a => a.RoleId == role.Id);

            context.Set <Role>().Remove(delRole);
        }
        public void Delete(DalRole e)
        {
            var role = e.ToOrmRole();

            role = _context.Set <Role>().Single(u => u.Id == role.Id);
            _context.Set <Role>().Remove(role);
        }
示例#6
0
        /// <summary>
        /// Add user to role
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="roleName">Name of applying role</param>
        /// <returns></returns>
        public async Task AddToRoleAsync(DalUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException(nameof(roleName));
            }

            var     roleStore = new DalRoleStore(context);
            DalRole dalRole   = await roleStore.FindByNameAsync(roleName);

            if (dalRole != null)
            {
                if (user.Roles == null)
                {
                    user.Roles = new List <DalRole>();
                }
                user.Roles.Clear();
                user.Roles.Add(dalRole);
                await UpdateAsync(user);
            }
        }
示例#7
0
        /// <summary>
        /// Removes user from specified role
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="roleName">Role name</param>
        /// <returns></returns>
        public Task RemoveFromRoleAsync(DalUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException(nameof(roleName));
            }

            if (user.Roles.Count == 0)
            {
                return(Task.FromResult <object>(null));
            }

            var     roleStore = new DalRoleStore(context);
            DalRole dalRole   = roleStore.FindByNameAsync(roleName).Result;

            if (dalRole != null)
            {
                if (user.Roles.Contains(dalRole))
                {
                    user.Roles.Remove(dalRole);
                    this.UpdateAsync(user);
                }
                return(Task.FromResult <object>(null));
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(roleName));
            }
        }
示例#8
0
        /// <summary>
        /// Check if user is in specifyed role
        /// </summary>
        /// <param name="user">User to check</param>
        /// <param name="roleName">Name of role</param>
        /// <returns>true - if user in role</returns>
        public Task <bool> IsInRoleAsync(DalUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException(nameof(roleName));
            }

            var     roleStore = new DalRoleStore(context);
            DalRole dalRole   = roleStore.FindByNameAsync(roleName).Result;

            if (dalRole != null)
            {
                if (user.Roles != null && user.Roles.Contains(dalRole))
                {
                    return(Task.FromResult <bool>(true));
                }
                else
                {
                    return(Task.FromResult <bool>(false));
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(roleName));
            }
        }
示例#9
0
 public static BllRole ToBllRole(this DalRole role)
 {
     return new BllRole()
     {
         RoleId = role.Id,
         Name = role.Name
     };
 }
示例#10
0
 public static Role ToOrmRole(this DalRole roleEntity)
 {
     return(new Role()
     {
         Id = roleEntity.Id,
         Name = roleEntity.Name
     });
 }
示例#11
0
 public static Role ToOrmRole(this DalRole role)
 {
     return(new Role
     {
         Id = role.Id,
         UserRoleName = role.UserRoleName
     });
 }
 public static RoleEntity ToBllRole(this DalRole dalRole)
 {
     return(new RoleEntity()
     {
         Id = dalRole.Id,
         Description = dalRole.Description
     });
 }
示例#13
0
 public static Role ToOrmRole(this DalRole dalRole)
 {
     return(new Role
     {
         RoleId = dalRole.Id,
         Name = dalRole.Name
     });
 }
示例#14
0
 public static BllRole ToBllRole(this DalRole dalRole)
 {
     return(new BllRole()
     {
         Id = dalRole.Id,
         Name = dalRole.Name
     });
 }
示例#15
0
 public void Delete(DalRole role)
 {
     if (ReferenceEquals(null, role))
     {
         throw new ArgumentNullException(nameof(role));
     }
     context.Context.Set <Roles>().Remove(context.Context.Set <Roles>().Single(u => u.RoleId == role.Id));
 }
 public static RoleEntity ToBllRoleEntity(this DalRole userRole)
 {
     return(new RoleEntity
     {
         UserRoleName = userRole.UserRoleName,
         Id = userRole.Id
     });
 }
示例#17
0
 public static DalRole ToOrmRole(this DalRole dalRole)
 {
     return(new DalRole()
     {
         Id = dalRole.Id,
         Name = dalRole.Name
     });
 }
示例#18
0
 public static BllRole ToBll(this DalRole role)
 {
     return(new BllRole
     {
         Id = role.Id,
         Name = role.Name
     });
 }
示例#19
0
 public Role MapToOrm(DalRole entity)
 {
     return(new Role
     {
         id = entity.Id,
         name = entity.Name
     });
 }
示例#20
0
 public static Role ToRole(this DalRole dalRole)
 {
     return(new Role()
     {
         Id = dalRole.Id,
         Name = dalRole.Name,
     });
 }
示例#21
0
 public void Create(DalRole role)
 {
     if (ReferenceEquals(null, role))
     {
         throw new ArgumentNullException(nameof(role));
     }
     context.Context.Set <Roles>().Add(role.ToRole());
 }
        /// <summary>
        /// Method convert role to DalRole.
        /// </summary>
        /// <param name="role">Entity that need convert.</param>
        /// <returns>Dal role.</returns>
        public static DalRole ToDalRole(this Role role)
        {
            DalRole dalRole = new DalRole {
                Name = role.Name
            };

            return(dalRole);
        }
示例#23
0
        public int Create(DalRole entity)
        {
            var obj = entity.ToOrmRole();

            context.Roles.Add(obj);
            context.SaveChanges();
            return(obj.RoleID);
        }
示例#24
0
 public static RoleEntity ToBllRole(this DalRole dalRole)
 {
     return(new RoleEntity()
     {
         Id = dalRole.Id,
         Name = dalRole.Name
     });
 }
 public void Delete(DalRole entity)
 {
     if (entity == null)
     {
         return;
     }
     Delete(entity.Id);
 }
 public void Create(DalRole entity)
 {
     if (entity == null)
     {
         return;
     }
     Context.Set <Role>()?.Add(entity.ToOrmRole());
 }
 /// <summary>
 /// Maps DalRole entity to  Role entity.
 /// </summary>
 /// <param name="role"> DalRole instance.</param>
 /// <returns> Role instance.</returns>
 public static Role ToRole(this DalRole role)
 {
     return(new Role()
     {
         Id = role.Id,
         Name = role.Name,
         Description = role.Description
     });
 }
示例#28
0
        public void Delete(DalRole e)
        {
            var role = _context.Roles.FirstOrDefault(x => x.Id == e.Id);

            if (role != null)
            {
                _context.Roles.Remove(role);
            }
        }
 public static Role ToBllRole(this DalRole dalRole)
 {
     return(new Role()
     {
         Id = dalRole.Id,
         Name = dalRole.Name,
         Description = dalRole.Description
     });
 }