Ejemplo n.º 1
0
        public async Task <Response> Post([FromBody] ExamenComplementarioTransfer examenComplementarioTransfer)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var examenComplementario = new ExamenComplementario
                {
                    IdExamenComplementario = examenComplementarioTransfer.IdExamenComplementario,
                    Fecha     = examenComplementarioTransfer.Fecha,
                    Resultado = examenComplementarioTransfer.Resultado,
                    IdTipoExamenComplementario = examenComplementarioTransfer.IdTipoExamenComplementario,
                    IdFichaMedica = examenComplementarioTransfer.IdFichaMedica,
                };

                var respuesta = Existe(examenComplementario);
                if (!respuesta.IsSuccess)
                {
                    db.ExamenComplementario.Add(examenComplementario);
                    await db.SaveChangesAsync();

                    var id = examenComplementario.IdExamenComplementario;

                    await uploadFileService.UploadFile(examenComplementarioTransfer.Fichero, "ExamenesComplementariosDocumentos", Convert.ToString(id), ".pdf");


                    var seleccionado = db.ExamenComplementario.Find(examenComplementario.IdExamenComplementario);
                    seleccionado.Url = string.Format("{0}/{1}.{2}", "ExamenesComplementariosDocumentos", Convert.ToString(id), "pdf");
                    db.ExamenComplementario.Update(seleccionado);
                    db.SaveChanges();
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
        public async Task <Response> DeleteDeclaracionPatrimonioPersonal([FromRoute] string id)
        {
            try
            {
                var ids = Convert.ToInt32(id);

                var modeloPatrimonio = await db.DeclaracionPatrimonioPersonal
                                       .Where(w => w.IdDeclaracionPatrimonioPersonal == ids)
                                       .FirstOrDefaultAsync();

                if (modeloPatrimonio == null)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.RegistroNoEncontrado
                    });
                }

                var modeloOtroIngreso = await db.OtroIngreso
                                        .Where(w => w.IdDeclaracionPatrimonioPersonal == modeloPatrimonio.IdDeclaracionPatrimonioPersonal)
                                        .FirstOrDefaultAsync();


                using (var transaction = await db.Database.BeginTransactionAsync())
                {
                    if (modeloOtroIngreso != null)
                    {
                        db.OtroIngreso.Remove(modeloOtroIngreso);
                    }


                    db.DeclaracionPatrimonioPersonal.Remove(modeloPatrimonio);
                    db.SaveChanges();

                    transaction.Commit();
                }
                return(new Response
                {
                    IsSuccess = true,
                    Message = Mensaje.BorradoSatisfactorio,
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.BorradoNoSatisfactorio,
                });
            }
        }
        public async Task <Response> InsertarFacturas([FromBody] ViewModelFacturaViatico viewModelFacturaViatico)
        {
            try
            {
                var documenttransfer = new FacturaViatico
                {
                    NumeroFactura      = viewModelFacturaViatico.NumeroFactura,
                    IdSolicitudViatico = viewModelFacturaViatico.IdSolicitudViatico,
                    IdItemViatico      = viewModelFacturaViatico.IdItemViatico,
                    FechaFactura       = viewModelFacturaViatico.FechaFactura,
                    ValorTotalFactura  = viewModelFacturaViatico.ValorTotalFactura,
                    Observaciones      = viewModelFacturaViatico.Observaciones,
                    Url = viewModelFacturaViatico.Url,
                };

                var respuesta = Existe(documenttransfer);
                if (!respuesta.IsSuccess)
                {
                    db.FacturaViatico.Add(documenttransfer);
                    await db.SaveChangesAsync();

                    var id = documenttransfer.IdFacturaViatico;

                    await uploadFileService.UploadFile(viewModelFacturaViatico.Fichero, "FacturaViaticos", Convert.ToString(id), ".pdf");


                    var seleccionado = db.FacturaViatico.Find(documenttransfer.IdFacturaViatico);
                    seleccionado.Url = string.Format("{0}/{1}.{2}", "FacturaViaticos", Convert.ToString(id), "pdf");
                    db.FacturaViatico.Update(seleccionado);
                    db.SaveChanges();
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
Ejemplo n.º 4
0
        public async Task <Response> Post([FromBody] NoticiaTransfer noticiaTransfer)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var noticia = new Noticia
                {
                    Titulo      = noticiaTransfer.Titulo,
                    Fecha       = noticiaTransfer.Fecha,
                    Descripcion = noticiaTransfer.Descripcion,
                };

                var respuesta = Existe(noticia);
                if (!respuesta.IsSuccess)
                {
                    Noticia objetoNoticia = await InsertarNoticia(noticia);

                    await uploadFileService.UploadFile(noticiaTransfer.Fichero, "Noticias", Convert.ToString(objetoNoticia.IdNoticia), "jpg");

                    var seleccionado = db.Noticia.Find(objetoNoticia.IdNoticia);
                    seleccionado.Foto = string.Format("{0}/{1}.{2}", "Noticias", Convert.ToString(objetoNoticia.IdNoticia), "jpg");
                    db.Noticia.Update(seleccionado);
                    db.SaveChanges();
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio,
                        Resultado = objetoNoticia
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.SwTH),
                    ExceptionTrace       = ex.Message,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
        public async Task <Response> Post([FromBody] DocumentoInstitucionalTransfer documentoInstitucionalTransfer)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var documentoInstitucional = new DocumentoInformacionInstitucional
                {
                    Nombre = documentoInstitucionalTransfer.Nombre,
                };

                var respuesta = Existe(documentoInstitucional.Nombre);
                if (!respuesta.IsSuccess)
                {
                    documentoInstitucional = await InsertarDocumentoInformacionInstitucional(documentoInstitucional);

                    await uploadFileService.UploadFile(documentoInstitucionalTransfer.Fichero, "Documentos", Convert.ToString(documentoInstitucional.IdDocumentoInformacionInstitucional), "pdf");


                    var seleccionado = db.DocumentoInformacionInstitucional.Find(documentoInstitucional.IdDocumentoInformacionInstitucional);
                    seleccionado.Url = string.Format("{0}/{1}.{2}", "Documentos", Convert.ToString(documentoInstitucional.IdDocumentoInformacionInstitucional), "pdf");
                    db.DocumentoInformacionInstitucional.Update(seleccionado);
                    db.SaveChanges();
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.SwTH),
                    ExceptionTrace       = ex.Message,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
        public async Task <Response> Post([FromBody] DocumentoInstitucionalTransfer documentoInstitucionalTransfer)
        {
            MaterialInduccion seleccionado = new MaterialInduccion();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var documentoInstitucional = new MaterialInduccion
                {
                    Titulo      = documentoInstitucionalTransfer.Nombre,
                    Descripcion = documentoInstitucionalTransfer.Descripcion
                };

                var respuesta = ExisteMaterialInduccion(documentoInstitucional);
                if (!respuesta.IsSuccess)
                {
                    if (documentoInstitucionalTransfer.Url == null)
                    {
                        documentoInstitucional = await InsertarMaterialInduccion(documentoInstitucional);

                        await uploadFileService.UploadFile(documentoInstitucionalTransfer.Fichero, "MaterialInduccion", Convert.ToString(documentoInstitucional.IdMaterialInduccion), documentoInstitucionalTransfer.Extension);


                        seleccionado     = db.MaterialInduccion.Find(documentoInstitucional.IdMaterialInduccion);
                        seleccionado.Url = string.Format("{0}/{1}{2}", "MaterialInduccion", Convert.ToString(documentoInstitucional.IdMaterialInduccion), documentoInstitucionalTransfer.Extension);
                        db.MaterialInduccion.Update(seleccionado);
                        db.SaveChanges();
                    }
                    else
                    {
                        documentoInstitucional = await InsertarMaterialInduccion(documentoInstitucional);

                        seleccionado     = db.MaterialInduccion.Find(documentoInstitucional.IdMaterialInduccion);
                        seleccionado.Url = documentoInstitucionalTransfer.Url;
                        db.MaterialInduccion.Update(seleccionado);
                        db.SaveChanges();
                    }

                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio,
                        Resultado = documentoInstitucional
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.SwTH),
                    ExceptionTrace       = ex.Message,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }