예제 #1
0
        public async Task <IActionResult> GetAsync()
        {
            var fileTypes = await this._repositoryManager
                            .FileTypeRepository.GetAsync();

            return(Ok(fileTypes.Select(ft => FileTypeMapper.Map(ft))));
        }
예제 #2
0
        public async Task <IActionResult> DeleteAsync([FromRoute] int id)
        {
            var fileType = await _repositoryManager
                           .FileTypeRepository.GetAsync(id);

            if (fileType == null)
            {
                return(NotFound());
            }

            _repositoryManager.FileTypeRepository.Delete(fileType);

            await _repositoryManager.SaveAsync();

            return(Ok(FileTypeMapper.Map(fileType)));
        }
예제 #3
0
        public async Task <IActionResult> CreateAsync([FromBody] InFileTypeDTO fileTypeDTO)
        {
            if (await _repositoryManager
                .FileTypeRepository.ExistsAsync(fileTypeDTO.Name))
            {
                return(BadRequest());
            }

            var fileType = FileTypeMapper.Map(fileTypeDTO);

            fileType = _repositoryManager.FileTypeRepository.Create(fileType);

            await _repositoryManager.SaveAsync();

            return(Ok(FileTypeMapper.Map(fileType)));
        }
예제 #4
0
        public async Task <IActionResult> UpdateAsync([FromRoute] int id,
                                                      [FromBody] InFileTypeDTO fileTypeDTO)
        {
            var fileType = await _repositoryManager
                           .FileTypeRepository.GetAsync(id);

            if (fileType == null)
            {
                return(NotFound());
            }

            fileType = _repositoryManager
                       .FileTypeRepository.Update(fileType, fileTypeDTO.Name);

            await _repositoryManager.SaveAsync();

            return(Ok(FileTypeMapper.Map(fileType)));
        }