public async Task <Response> GetFile([FromBody] DocumentoInformacionInstitucional documentoInformacionInstitucional)
        {
            try
            {
                var respuestaFile = uploadFileService.GetFile("Documentos", Convert.ToString(documentoInformacionInstitucional.IdDocumentoInformacionInstitucional), "pdf");

                var documentoIstitucional = await db.DocumentoInformacionInstitucional.Where(x => x.IdDocumentoInformacionInstitucional == documentoInformacionInstitucional.IdDocumentoInformacionInstitucional).FirstOrDefaultAsync();

                return(new Response
                {
                    IsSuccess = true,
                    Message = documentoIstitucional.Nombre,
                    Resultado = respuestaFile,
                });
            }
            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,
                });
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(ViewModelDocumentoInstitucional view, List <IFormFile> files)
        {
            if (files.Count > 0)
            {
                byte[] data;
                using (var br = new BinaryReader(files[0].OpenReadStream()))
                    data = br.ReadBytes((int)files[0].OpenReadStream().Length);

                var documenttransfer = new DocumentoInstitucionalTransfer
                {
                    Nombre  = view.Nombre,
                    Fichero = data,
                };

                var respuesta = await CreateFichero(documenttransfer);

                if (respuesta.IsSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewData["Error"] = respuesta.Message;

                    var documento = new DocumentoInformacionInstitucional
                    {
                        Nombre = view.Nombre,
                    };
                    return(View(documento));
                }
            }

            return(BadRequest());
        }
Exemplo n.º 3
0
        public async Task <FileResult> Download(string id)
        {
            var d = new DocumentoInformacionInstitucional
            {
                IdDocumentoInformacionInstitucional = Convert.ToInt32(id),
            };

            var response = await apiServicio.ObtenerElementoAsync(d,
                                                                  new Uri(WebApp.BaseAddress),
                                                                  "api/DocumentosInformacionInstitucional/GetFile");

            var m        = JsonConvert.DeserializeObject <DocumentoInstitucionalTransfer>(response.Resultado.ToString());
            var fileName = $"{ response.Message}.pdf";

            return(File(m.Fichero, "application/pdf", fileName));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(string id, DocumentoInformacionInstitucional documentoInformacionInstitucional)
        {
            Response response = new Response();

            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    response = await apiServicio.EditarAsync(id, documentoInformacionInstitucional, new Uri(WebApp.BaseAddress),
                                                             "api/DocumentosInformacionInstitucional");

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                            EntityID             = string.Format("{0} : {1}", "documento de información institucional", id),
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                            Message  = "Se ha actualizado un documento de información institucional",
                            UserName = "******"
                        });

                        return(RedirectToAction("Index"));
                    }
                    ViewData["Error"] = response.Message;
                    return(View(documentoInformacionInstitucional));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Editando un documento de información institucional",
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
        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> PutDocumentoInformacionInstitucional([FromRoute] int id, [FromBody] DocumentoInformacionInstitucional documentoInformacionInstitucional)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                var existe = Existe(documentoInformacionInstitucional.Nombre);
                if (existe.IsSuccess)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ExisteRegistro,
                    });
                }

                var documentoInformacionInstitucionalActualizar = await db.DocumentoInformacionInstitucional.Where(x => x.IdDocumentoInformacionInstitucional == id).FirstOrDefaultAsync();

                if (documentoInformacionInstitucionalActualizar != null)
                {
                    try
                    {
                        documentoInformacionInstitucionalActualizar.Nombre = documentoInformacionInstitucional.Nombre;
                        await db.SaveChangesAsync();

                        return(new Response
                        {
                            IsSuccess = true,
                            Message = Mensaje.Satisfactorio,
                        });
                    }
                    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,
                        });
                    }
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }
        // POST: api/BasesDatos
        private async Task <DocumentoInformacionInstitucional> InsertarDocumentoInformacionInstitucional(DocumentoInformacionInstitucional DocumentoInformacionInstitucional)
        {
            db.DocumentoInformacionInstitucional.Add(DocumentoInformacionInstitucional);
            await db.SaveChangesAsync();

            return(DocumentoInformacionInstitucional);
        }