public async Task <IActionResult> GET_ALL_ROLES() { var query = new GetAllRolesQuery(); var response = await _mediator.Send(query); return(Ok(response)); }
public async Task <List <RoleModel> > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { var user = await userStore.FindByIdAsync(request.GetUser(), cancellationToken); if (user == null) { throw new Exceptions.UserDoesNotExistException(); } var roleDb = await _roleRepository.GetAllRolesAsync(); var workersDb = await _workerRepository.GetAllWorkersAsync(); var groupByRoleId = workersDb .GroupBy(x => x.Role) .Select(w => new RoleModel(w.Key.RoleId, w.Count()) ); var response = roleDb.Select(x => new RoleModel(roleId: x.RoleId, roleName: x.Name, abbreviation: x.Abbreviation) { TotalWorkers = groupByRoleId.Any(y => y.RoleId == x.RoleId) ? groupByRoleId.Where(y => y.RoleId == x.RoleId).Select(y => y.TotalWorkers).FirstOrDefault() : 0 }) .ToList(); return(response); }
public async Task <List <RoleDto> > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { //var roleEntities = await _genericRepo.GetAllAsync<ApplicationRole>(_ => true); var roleEntities = _roleManager.Roles.ToList(); var roles = _mapper.Map <IEnumerable <RoleDto> >(roleEntities).ToList(); return(roles); }
public async Task <IEnumerable <IdentityRole> > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { return(roleManager.Roles); //var qry = // from r in roleManager.Roles // select new GetAllRolesQueryDto() // { // Id = r.Id, // Name = r.Name // }; //return qry; }
public RolController( CreateRoleCommandHandler createCommand, GetAllRolesQuery getAllQuery, GetRoleQuery getOneQuery, UpdateRoleCommandHandler updateCommand, DeleteRoleCommandHandler deleteCommand) { this.createCommand = createCommand; this.getAllQuery = getAllQuery; this.getOneQuery = getOneQuery; this.updateCommand = updateCommand; this.deleteCommand = deleteCommand; }
public async Task <DataResult <IEnumerable <ApplicationRole> > > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { var roles = await _rolesRepository.GetAll(); if (roles.Success) { return(new DataResult <IEnumerable <ApplicationRole> >(roles.GetData())); } else { return(new DataResult <IEnumerable <ApplicationRole> >(success: false)); } }
/// <inheritdoc /> public async Task <IReadOnlyList <RoleDto> > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { try { return(await _roleService.GetAllAsync(cancellationToken)); } catch (BaseException) { throw; } catch (Exception ex) { throw new WebSshServiceException(_localizer[RolesConstants.GettingRolesError].Value, ex); } }
public async Task <ActionResult <RoleModel> > GetAllRoleAsync([FromQuery] GetAllRolesQuery request) { try { request.SetUser(User.GetUserId()); var response = await _mediator.Send(request); return(Ok(response)); } catch (Exception ex) { _logger.Error(ex, $"Operation failed into controller {Routes.Get_All_Roles} with message: {ex.Message}"); return(BadRequest(ex.Message)); } }
public async Task <MultipleRolesQueryResponse> GetAllRoles(UserRole currentRole) { var query = new GetAllRolesQuery(currentRole); return(await _mediator.Send(query)); }
public async override Task <List <RoleReadModel> > Execute(GetAllRolesQuery input, User?user) { var roles = await reader.ReadAll(); return(roles); }
public async Task <List <GetAllRolesDto> > Handle(GetAllRolesQuery request, CancellationToken cancellationToken) { var result = mapper.Map <List <GetAllRolesDto> >(await context.Roles.ToListAsync()); return(result); }