コード例 #1
0
        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();
        }
コード例 #2
0
 public async Task <IActionResult> GetMaterials([FromQuery] FilterMaterial filter)
 {
     return(await Ok(() => _serviceMaterial.GetMaterialsAsync(filter)));
 }