public async Task <IActionResult> DeleteUserROle(UserRoleRequest request) { //Recupero l'elemento dal business layer var entity = AuthorizationLayer.GetUserRole(request.UserRoleId); //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo if (entity == null) { return(NotFound()); } //Invocazione del service layer var validations = await AuthorizationLayer.DeleteUserRole(entity, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } var userRoles = AuthorizationLayer.FetchUserRole(entity.RoleId); var userIds = userRoles.Select(x => x.UserId).ToList(); var users = BasicLayer.FetchShootersByIds(userIds); //Return contract return(Ok(userRoles.As(x => ContractUtils.GenerateContract(x, users?.FirstOrDefault(s => s.Id == x.UserId))))); }
public async Task <IActionResult> CreateUserRole(UserRoleCreateRequest request) { //Recupero l'elemento dal business layer var user = BasicLayer.GetShooter(request.UserId); if (user == null) { return(NotFound($"User with {request.UserId} not found")); } //Recupero l'elemento dal business layer var role = AuthorizationLayer.GetRole(request.RoleId); if (role == null) { return(NotFound($"Role with {request.RoleId} not found")); } var entity = new UserRole() { UserId = user.Id, RoleId = role.Id, EntityId = request.EntityId }; //Invocazione del service layer var validations = await AuthorizationLayer.CreateUserRole(entity, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } var userRoles = AuthorizationLayer.FetchUserRole(role.Id); var userIds = userRoles.Select(x => x.UserId).ToList(); var users = BasicLayer.FetchShootersByIds(userIds); //Return contract return(Ok(userRoles.As(x => ContractUtils.GenerateContract(x, users?.FirstOrDefault(s => s.Id == x.UserId))))); }
public Task <IActionResult> GetRole(RoleRequest request) { var entity = AuthorizationLayer.GetRole(request.RoleId); //verifico validità dell'entità if (entity == null) { return(Task.FromResult <IActionResult>(NotFound())); } var permissions = AuthorizationLayer.FetchPermissionsOnRole(entity.Id); var userRoles = AuthorizationLayer.FetchUserRole(entity.Id); var userIds = userRoles.Select(x => x.UserId).ToList(); var users = BasicLayer.FetchShootersByIds(userIds); //Serializzazione e conferma return(Reply(ContractUtils.GenerateContract(entity, permissions, userRoles, users))); }