Esempio n. 1
0
        public async Task <MemoDTO> GetByIdAsync(Guid id)
        {
            var memo = await _memoRepository.GetByIdAsync(id);

            if (memo == null)
            {
                throw new Exception($"Memo with id: {id} does not exists.");
            }

            return(_mapper.Map <MemoDTO>(memo));
        }
Esempio n. 2
0
        /// <summary>
        /// 게시판 파일 강제 다운로드 기능(/BoardDown/:Id)
        /// </summary>
        public async Task <IActionResult> FileDown(int id)
        {
            var model = await _repository.GetByIdAsync(id);

            if (model == null)
            {
                return(null);
            }
            else
            {
                if (!string.IsNullOrEmpty(model.FileName))
                {
                    byte[] fileBytes = await _fileStorageManager.DownloadAsync(model.FileName, "Memos");

                    if (fileBytes != null)
                    {
                        model.DownCount = model.DownCount + 1;
                        await _repository.EditAsync(model);

                        return(File(fileBytes, "application/octet-stream", model.FileName));
                    }
                    else
                    {
                        return(Redirect("/"));
                    }
                }

                return(Redirect("/"));
            }
        }
Esempio n. 3
0
        [HttpGet("{id:int}", Name = nameof(GetMemoById))] // Name 속성으로 RouteName 설정
        public async Task <IActionResult> GetMemoById([FromRoute] int id)
        {
            try
            {
                var model = await _repository.GetByIdAsync(id);

                if (model == null)
                {
                    //return new NoContentResult(); // 204 No Content
                    return(NotFound());
                }
                return(Ok(model));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(BadRequest());
            }
        }