コード例 #1
0
        public async Task <ActionResult <ContractForGetDTO> > Put(int id, ContractForEditDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

            if (!await _contractRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Contract", id))));
            }

            if (await _contractRepository.IsExist(model.Id, model.Name).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            Contract oldContract = await _contractRepository.GetAsync(id).ConfigureAwait(true);

            Contract contract = _mapper.Map <Contract>(model);

            contract.PdfName = oldContract.PdfName;
            _contractRepository.Edit(contract);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }
コード例 #2
0
        public async Task <ActionResult <ContractForGetDTO> > Get(int id)
        {
            if (!await _contractRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Contract", id))));
            }

            Contract contract = await _contractRepository.GetAsync(id).ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }
コード例 #3
0
        public async Task <ActionResult <ContractForGetDTO> > Post(ContractForAddDTO model)
        {
            if (await _contractRepository.IsExist(model.Name).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            Contract contract = _mapper.Map <Contract>(model);

            await _contractRepository.AddAsync(contract).ConfigureAwait(true);

            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }
コード例 #4
0
        public async Task <ActionResult <ContractForGetDTO> > Delete(int id)
        {
            if (!await _contractRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Contract", id))));
            }

            Contract contract = await _contractRepository.GetAsync(id).ConfigureAwait(true);

            _contractRepository.Remove(contract);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            FolderOperations.DeleteFolder($"Contracts/{id}");

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }
コード例 #5
0
        public async Task <ActionResult> UploadPdf(int id, [FromForm] ContractForFileDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

            if (!await _contractRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Contracts", id))));
            }

            FileOperations.WriteFile($"Contracts/{model.Id}", model.Pdf);

            Contract contract = await _contractRepository.GetAsync(model.Id).ConfigureAwait(true);

            contract.PdfName = model.Pdf.FileName;
            _contractRepository.Edit(contract);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }