public async Task <PagedData <Material> > GetMaterialsAsync(FilterMaterial filter) { var user = await Context.GetCurrentUserAsync(); if (user.IsAdmin()) { var specification = new MaterialsByName(filter.Name); var(count, materials) = await _repositoryMaterial.FindPaginatedAsync(specification, filter); return(new PagedData <Material>(Mapper.Map <List <Material> >(materials), count)); } if (user.IsLecturer()) { var specification = new MaterialsByName(filter.Name) & new MaterialsByOwnerId(user.Id); var(count, materials) = await _repositoryMaterial.FindPaginatedAsync(specification, filter); return(new PagedData <Material>(Mapper.Map <List <Material> >(materials), count)); } throw ExceptionHelper.NoAccess(); }
public async Task <IActionResult> GetMaterials([FromQuery] FilterMaterial filter) { return(await Ok(() => _serviceMaterial.GetMaterialsAsync(filter))); }