示例#1
0
        public int Create(RoleItem role)
        {
            using (SqlHelper sqlh = new SqlHelper(@"
            insert into Access.role(code, mem)
            values (@Code, @Mem)

            select SCOPE_IDENTITY()
            "))
            {
                sqlh.AddWithValue("@Code", role.Code);
                sqlh.AddWithValue("@Mem", role.Mem);
                return (int)sqlh.ExecScalar();
            }
        }
示例#2
0
文件: RoleService.cs 项目: dha01/IS
        /// <summary>
        /// Создает роль.
        /// </summary>
        /// <param name="task">Роль.</param>
        /// <returns>Идентификаторо созданной роли.</returns>
        public int Create(RoleItem role)
        {
            if (string.IsNullOrEmpty(role.Code))
            {
                throw new Exception("Поле 'Code' не должно быть пустым.");
            }

            if (string.IsNullOrEmpty(role.Mem))
            {
                throw new Exception("Поле 'Mem' не должно быть пустым.");
            }

            return _roleRepository.Create(role);
        }
示例#3
0
        /// <summary>
        /// Создает новую роль.
        /// </summary>
        /// <param name="role">Роль.</param>
        /// <returns>Идентификатор созданной роли.</returns>
        public int Create(RoleItem role)
        {
            using (var sqlh = new SqlHelper())
            {
                return sqlh.ExecScalar<int>(@"
            insert into Access.role
            (
            code,
            mem
            )
            values
            (
            @Code,
            @Mem
            )

            select scope_identity()", role);
            }
        }
示例#4
0
        public bool CheckRole(RoleItem role)
        {
            var user = GetCurrentUser();
            if (user == null)
            {
                return false;
            }

            if (role == null)
            {
                return true;
            }

            if (!UserInRole(user, role))
            {
                return false;
            }

            return true;
        }
示例#5
0
        public void GetListByOwnerRole_Void_ReturnNotEmptyListWithRoles()
        {
            RoleItem roleOne = new RoleItem()
            {
                Code = "Test1",
                Mem = "Test1"
            };
            RoleItem roleTwo = new RoleItem()
            {
                Code = "Test2",
                Mem = "Test3"
            };

            _role.Id = _roleRepository.Create(_role);
            roleOne.Id = _roleRepository.Create(roleOne);
            roleTwo.Id = _roleRepository.Create(roleTwo);

            _roleRepository.CreateMemberRole(_role.Id, roleOne.Id);
            _roleRepository.CreateMemberRole(_role.Id, roleTwo.Id);

            var result = _roleRepository.GetListByOwnerRole(_role);

            AreEqualRoles(result.First(x => x.Id == roleTwo.Id), roleTwo);
            AreEqualRoles(result.First(x => x.Id == roleOne.Id), roleOne);
            AreEqualRoles(result.First(x => x.Id == _role.Id), _role);
        }
示例#6
0
 /// <summary>
 /// Проверяет эквивалентны ли две роли.
 /// </summary>
 /// <param name="first_role">Первая роль.</param>
 /// <param name="second_role">Вторая роль.</param>
 private void AreEqualRoles(RoleItem first_role, RoleItem second_role)
 {
     Assert.AreEqual(first_role.Id, second_role.Id);
     Assert.AreEqual(first_role.Code, second_role.Code);
     Assert.AreEqual(first_role.Mem, second_role.Mem);
 }
示例#7
0
        public void SetUp()
        {
            _transactionScope = new TransactionScope();
            _roleRepository = new RoleRepository();

            _role = new RoleItem()
            {
                Code = "test",
                Mem = "tester"
            };
            _roleNew = new RoleItem()
            {
                Code = "test2",
                Mem = "tester2"
            };
        }
示例#8
0
 public void Update(RoleItem role)
 {
     using (SqlHelper sqlh = new SqlHelper(@"
     update Access.role
     set
     code = @Code,
     mem = @Mem
     where role = @Id"))
     {
         sqlh.AddWithValue("@Id", role.Id);
         sqlh.AddWithValue("@Code", role.Code);
         sqlh.AddWithValue("@Mem", role.Mem);
         sqlh.ExecNoQuery();
     }
 }
示例#9
0
文件: Access.cs 项目: BaTpyLLI/IS
 public static bool UserInRole(UserItem user, RoleItem role)
 {
     return _accessService.UserInRole(user, role);
 }
示例#10
0
 public ActionResult Create(RoleItem role)
 {
     Access.CheckAccess("Role.Creator");
     return RedirectToAction("Index", new { id = _roleService.Create(role) });
 }
示例#11
0
文件: RoleService.cs 项目: dha01/IS
        /// <summary>
        /// Измененяет данные о роли.
        /// </summary>
        /// <param name="role">Роль.</param>
        public void Update(RoleItem role)
        {
            if (string.IsNullOrEmpty(role.Code))
            {
                throw new Exception("Поле 'Code' не должно быть пустым.");
            }

            if (string.IsNullOrEmpty(role.Mem))
            {
                throw new Exception("Поле 'Mem' не должно быть пустым.");
            }

            if (GetById(role.Id) == null)
            {
                throw new Exception("Роль не найдена.");
            }

            _roleRepository.Update(role);
        }
示例#12
0
文件: AccessService.cs 项目: dha01/IS
 public bool UserInRole(UserItem user, RoleItem role)
 {
     var list = _roleRepository.GetListByUser(user);
     return list.Exists(x => x.Code == "Admin" || role.Code.StartsWith(x.Code));
 }
示例#13
0
 /// <summary>
 /// Обновляет данные по роли.
 /// </summary>
 /// <param name="role">Роль.</param>
 public void Update(RoleItem role)
 {
     using (var sqlh = new SqlHelper())
     {
         sqlh.ExecNoQuery(@"
     update Access.role
     set
     code = @Code,
     mem = @Mem
     where role = @Id", role);
     }
 }
示例#14
0
 /// <summary>
 /// Получает список подролей по роли.
 /// </summary>
 /// <param name="role">Роль.</param>
 /// <returns>Список ролей.</returns>
 public List<RoleItem> GetListByOwnerRole(RoleItem role)
 {
     using (var sqlh = new SqlHelper())
     {
         return sqlh.ExecMappingList<RoleItem>(@"
     select
     r.role Id,
     r.code Code,
     r.mem Mem
     from Access.role r
     join Access.role_member m on m.role_offer = r.role
     where m.role_owner = @Id", role);
     }
 }
示例#15
0
        public void SetUp()
        {
            _roleRepository = Mock.Of<IRoleRepository>();
            _roleService = new RoleService(_roleRepository);

            _role = new RoleItem()
            {
                Id = 1,
                Code = "IT",
                Mem = "IT about"
            };
        }
示例#16
0
 public bool UserInRole(UserItem user, RoleItem role)
 {
     var list = _roleRepository.GetListByUser(user);
     return list.Exists(x => x.Code == "Admin" || x.Id == role.Id);
 }
示例#17
0
文件: Access.cs 项目: BaTpyLLI/IS
 public static void CheckRole(RoleItem role)
 {
     _accessService.CheckRole(role);
 }
示例#18
0
 public ActionResult Update(RoleItem role)
 {
     Access.CheckAccess("Role.Updater");
     _roleService.Update(role);
     return RedirectToAction("Index", new { id = role.Id });
 }