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(); } }
/// <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); }
/// <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); } }
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; }
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); }
/// <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); }
public void SetUp() { _transactionScope = new TransactionScope(); _roleRepository = new RoleRepository(); _role = new RoleItem() { Code = "test", Mem = "tester" }; _roleNew = new RoleItem() { Code = "test2", Mem = "tester2" }; }
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(); } }
public static bool UserInRole(UserItem user, RoleItem role) { return _accessService.UserInRole(user, role); }
public ActionResult Create(RoleItem role) { Access.CheckAccess("Role.Creator"); return RedirectToAction("Index", new { id = _roleService.Create(role) }); }
/// <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); }
public bool UserInRole(UserItem user, RoleItem role) { var list = _roleRepository.GetListByUser(user); return list.Exists(x => x.Code == "Admin" || role.Code.StartsWith(x.Code)); }
/// <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); } }
/// <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); } }
public void SetUp() { _roleRepository = Mock.Of<IRoleRepository>(); _roleService = new RoleService(_roleRepository); _role = new RoleItem() { Id = 1, Code = "IT", Mem = "IT about" }; }
public bool UserInRole(UserItem user, RoleItem role) { var list = _roleRepository.GetListByUser(user); return list.Exists(x => x.Code == "Admin" || x.Id == role.Id); }
public static void CheckRole(RoleItem role) { _accessService.CheckRole(role); }
public ActionResult Update(RoleItem role) { Access.CheckAccess("Role.Updater"); _roleService.Update(role); return RedirectToAction("Index", new { id = role.Id }); }