public async Task <IActionResult> Update(int id, [FromBody] DocumentUpdateDTO documentDTO)
        {
            try
            {
                if (id < 1 || documentDTO == null || id != documentDTO.IDDocument)
                {
                    return(BadRequest());
                }

                var isExists = await _documentRepository.isExists(id);

                if (!isExists)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var document  = _mapper.Map <Document>(documentDTO);
                var isSuccess = await _documentRepository.Update(document);

                if (!isSuccess)
                {
                    return(InternalError($"Update operation failed."));
                }
                return(NoContent());
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message} - {e.InnerException}"));
            }
        }
        public ActionResult UpdateDocuemnt(int id, DocumentUpdateDTO updateDTO)
        {
            var document = _repoContext.GetDocumentByID(id);

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

            _mapper.Map(updateDTO, document);
            _repoContext.UpdateDocuemt(document);
            _repoContext.SaveChanges();
            return(NoContent());
        }
Example #3
0
 public async Task <ActionResult <DocumentDTO> > UpdateAsync([FromBody] DocumentUpdateDTO document)
 {
     try
     {
         return(Ok(await documentService.UpdateAsync(document)));
     }
     catch (NotFoundException e)
     {
         return(NotFound(new { Id = e.Key, e.Message }));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.ValidationErrors));
     }
 }