public async Task DeleteAsync(RoleClaim entity) { await Connection.ExecuteAsync ( sql : @" DELETE FROM [RoleClaims] WHERE Id = @Id ", param : new { Id = entity.Id }, transaction : Transaction ); await Connection.ExecuteAsync ( sql : @" DELETE FROM [Claims] WHERE Id = @Id ", param : new { Id = entity.Id }, transaction : Transaction ); }
public async Task AddClaimAsync(Role role, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken != null) { cancellationToken.ThrowIfCancellationRequested(); } if (role == null) { throw new ArgumentNullException(nameof(role)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var roleClaimEntity = new RoleClaim { ClaimType = claim.Type, ClaimValue = claim.Value, RoleId = role.Id }; await _roleClaimService.AddAsync(roleClaimEntity); return; }
public IHttpActionResult AddRoleClaim([FromUri] Guid roleId, [FromBody] ClaimModel model) { if (ModelState.IsValid) { try { var role = Context.Roles.Find(roleId); if (role != null) { var claim = new RoleClaim { Type = model.Type, Value = model.Value, RoleId = role.Id }; role.RoleClaims.Add(claim); Context.SaveChanges(); return(Ok()); } ModelState.AddModelError("", $"Invalid {nameof(roleId)}"); } catch (Exception ex) { return(InternalServerError(ex)); } } return(BadRequest(ModelState)); }
public Task AddClaimAsync(IdentityRole role, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken != null) { cancellationToken.ThrowIfCancellationRequested(); } if (role == null) { throw new ArgumentNullException(nameof(role)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var roleClaimEntity = new RoleClaim { ClaimType = claim.Type, ClaimValue = claim.Value, RoleId = role.Id }; _unitOfWork.RoleClaimRepository.Add(roleClaimEntity); _unitOfWork.Commit(); return(Task.CompletedTask); }
public bool Update(RoleClaim _obj) { caciDbContent.RoleClaim.Update(_obj); return(caciDbContent.SaveChanges() > 0); }
public async Task AddClaimToRole(ulong roleId, ulong claimId) { RoleClaim roleClaim = new RoleClaim { Role = roleId, Claim = claimId }; await _roleClaimRepository.Add(roleClaim); }
public async Task <RoleClaimView> ManageRoleClaims(string roleId) { var role = await _roleManager.FindByIdAsync(roleId); var existingRoleClaims = await _roleManager.GetClaimsAsync(role); var model = new RoleClaimView { RoleId = roleId }; foreach (var claim in ClaimsRepository.AllClaims) { RoleClaim roleClaim = new RoleClaim { ClaimType = claim.Type }; if (existingRoleClaims.Any(c => c.Type == claim.Type)) { roleClaim.IsSelected = true; } model.Claims.Add(roleClaim); } return(model); }
public RoleClaim Create(RoleClaim newRoleClaim) { newRoleClaim = _roleClaimDbController.Create(newRoleClaim); _logger.LogInformation($"RoleId: {newRoleClaim?.RoleId}, ClaimId: {newRoleClaim?.ClaimId}"); return(newRoleClaim); }
public Claim Map(RoleClaim entity) { return(new Common.DTO.Claim { Type = entity.ClaimType, Value = entity.ClaimValue }); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; var roleClaim = new RoleClaim { ClaimType = "Claim Type", ClaimValue = "Claim Value" }; var role = new Role { Name = "Role Name", RoleClaims = new List <RoleClaim> { roleClaim } }; using (var context = new OidcDbContext(options)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } IActionResult get; // Act using (var context = new OidcDbContext(options)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); var model = new ClaimsModel(_roleManager.Object) { Role = new Role { Id = role.Id } }; get = await model.OnPostAsync().ConfigureAwait(false); } // Assert _roleManager.Verify( x => x.RemoveClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim.ClaimType) && y.Value.Equals(roleClaim.ClaimValue))), Times.Once); var result = Assert.IsType <RedirectToPageResult>(get); Assert.Equal("../Details/Claims", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Role.Id), key); Assert.Equal(role.Id, value); }); }
public void RoleClaimSetValue_ExpectsValue(string value) { var roleClaim = new RoleClaim { ClaimValue = value }; roleClaim.ClaimValue.Should().Be(value); }
public int AddClaim(Role role, RoleClaim claim) { IRoleClaimRepository repo = _data_repository_factory.GetIdentityDataRepository <IRoleClaimRepository>(); return(repo.Save(new RoleClaimData() { Id = claim.ClaimID, RoleID = role.RoleId, ClaimType = claim.ClaimType, ClaimValue = claim.ClaimValue })); }
public RoleClaim Create(RoleClaim roleClaim) { using (var context = ContextFactory.Create()) { context.RoleClaims.Add(roleClaim); context.SaveChanges(); return(roleClaim); } }
public void RoleSetRoleId_ExpectsValue() { var value = "testid"; var role = new RoleClaim { RoleId = value }; role.RoleId.Should().Be(value); }
public void RoleClaimSetId_ExpectsValue() { int value = 10; var roleClaim = new RoleClaim { Id = value }; roleClaim.Id.Should().Be(value); }
public static ClaimModel FromEntity(RoleClaim claim) { return(new ClaimModel { Id = claim.Id, Type = claim.Type, Value = claim.Value, Role = claim.Role, }); }
public void Add(RoleClaim entity) { entity.Id = ExecuteScalar <int>( sql: @" INSERT INTO AspNetRoleClaims(ClaimType, ClaimValue, RoldId) VALUES(@ClaimType, @ClaimValue, @RoldId); SELECT SCOPE_IDENTITY()", param: entity ); }
public void Update(RoleClaim entity) { Execute( sql: @" UPDATE AspNetRoleClaims SET ClaimType = @ClaimType, ClaimValue = @ClaimValue, RoleId = @RoleId WHERE Id = @Id", param: entity ); }
public void Instance_Implement_Interface_IHaveDateAndTimeOfCreation() { //Arrange var type = typeof(IHaveDateAndTimeOfCreation); //Act var roleClaim = new RoleClaim(); //Assert Assert.IsInstanceOf(type, roleClaim); }
public async Task AddRoleClaimAsync(RoleClaim roleClaim, CancellationToken token) { using SqlConnection con = await GetConnectionAsync(token); using SqlCommand cmd = con.StoredProcedure("AddRoleClaim"); cmd.Parameters.AddWithValue("@roleId", roleClaim.RoleId); cmd.Parameters.AddWithValue("@claimType", roleClaim.ClaimType, null); cmd.Parameters.AddWithValue("@claimValue", roleClaim.ClaimValue, null); await cmd.ExecuteNonQueryAsync(token); }
public void Instance_Is_IdentityRoleClaim_Of_Integer() { //Arrange var type = typeof(IdentityRoleClaim <int>); //Act var roleClaim = new RoleClaim(); //Assert Assert.IsInstanceOf(type, roleClaim); }
public void Create(RoleClaimRequest request) { var claim = new RoleClaim { ClaimType = request.ClaimType, RoleId = request.RoleId, ClaimValue = request.ClaimValue }; _roleClaimRepository.Add(claim); }
public bool Delete(int id) { RoleClaim caseToRemove = new RoleClaim() { RoleClaimId = id }; caciDbContent.RoleClaim.Attach(caseToRemove); caciDbContent.RoleClaim.Remove(caseToRemove); return(caciDbContent.SaveChanges() > 0); }
public async Task <IActionResult> AddRoleClaimAsync(RoleClaim _roleClaim) { var _role = await _roleManager.FindByNameAsync(_roleClaim.RoleName); if (_role == null) { return(BadRequest("RoleName does Not exsit")); } await _roleManager.AddClaimAsync(_role, new Claim(_roleClaim.Claim.Type, _roleClaim.Claim.Value)); return(Ok()); }
public static RoleClaimResponse ToContract(this RoleClaim roleClaimModel) { if (roleClaimModel == null) { return(null); } return(new RoleClaimResponse { RoleId = roleClaimModel.RoleId, ClaimId = roleClaimModel.ClaimId }); }
private RoleClaim ReadRoleClaim(IDataReader rdr) { RoleClaim roleClaim = new RoleClaim { Id = rdr.GetValue <int>("Id"), RoleId = rdr.GetValue <int>("RoleId"), ClaimType = rdr.GetValue <string>("ClaimType"), ClaimValue = rdr.GetValue <string>("ClaimValue"), }; return(roleClaim); }
public void RoleClaim_Default_Constructor() { // Arrange // Act var roleClaim = new RoleClaim(); // Assert roleClaim.RoleId.Should().BeEmpty(); roleClaim.Role.Should().BeNull(); roleClaim.ClaimId.Should().BeEmpty(); roleClaim.Claim.Should().BeNull(); }
public void Remove(RoleClaimRequest request) { var claim = new RoleClaim { ClaimType = request.ClaimType, RoleId = request.RoleId, ClaimValue = request.ClaimValue, Id = request.Id }; _roleClaimRepository.Delete(claim); }
public async Task <IActionResult> Manage(Guid id) { Role role = await _roleManager.FindByIdAsync(id.ToString()); if (role == null) { return(View("Error")); } ViewBag.role = role; Dictionary <string, List <ManageRoleClaimsViewModel> > model = new Dictionary <string, List <ManageRoleClaimsViewModel> >(); List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(); foreach (EClaim claim in Enum.GetValues(typeof(EClaim))) { #region Skip Superadmin permission giving for any role bool condition = claim.ToString().Length < 11 ? false : claim.ToString().Substring(0, 11) == "SuperAdmin_"; if (condition) { continue; } #endregion RoleClaim roleClaim = await _context.RoleClaims .Where(rc => rc.ClaimType == claim.ToString()) .Where(rc => rc.ClaimValue == claim.Description()) .Where(rc => rc.RoleId == role.Id) .FirstOrDefaultAsync(); ManageRoleClaimsViewModel roleClaimsViewModel = new ManageRoleClaimsViewModel { RoleId = role.Id, ClaimType = claim.ToString(), ClaimValue = claim.Description() }; if (roleClaim == null) { roleClaimsViewModel.Selected = false; } else { roleClaimsViewModel.Id = roleClaim.Id; roleClaimsViewModel.Selected = true; } string moduleName = claim.ToString().Split("_").FirstOrDefault(); if (!model.ContainsKey(moduleName)) { model.Add(moduleName, new List <ManageRoleClaimsViewModel>()); } model[moduleName].Add(roleClaimsViewModel); } return(View(model)); }
public bool Adicionar(RoleClaim roleClaim) { _repositorio.Adicionar(roleClaim); if (roleClaim.id > 0) { return(true); } else { return(false); } }