Пример #1
0
 public async Task <IActionResult> Add([FromBody] DocumentoAddModel model)
 {
     try
     {
         return(new OkObjectResult(await _documentoService.Add(model)));
     }
     catch (Exception ex)
     {
         return(new OkObjectResult(
                    new ResponseDocumentoAddModel {
             Documento = null, Message = ex.Message, Success = false
         }
                    ));
     }
 }
Пример #2
0
        public async Task <ResponseDocumentoAddModel> Add(DocumentoAddModel model)
        {
            // TODO: Validation: (CPF e Id não podem ser repetidos)

            try
            {
                var documentoEntity = _mapper.Map <DocumentoEntity>(model);

                var documentoEntityDb = await _documentoRepository.Insert(documentoEntity);

                _uow.SaveChanges();

                return(new ResponseDocumentoAddModel {
                    Documento = _mapper.Map <DocumentoModel>((DocumentoEntity)documentoEntityDb.Entity), Message = "Documento Registrado com Sucesso", Success = true
                });
            }
            catch (Exception ex)
            {
                return(new ResponseDocumentoAddModel {
                    Documento = null, Message = ex.Message, Success = false
                });
            }
        }