public IHttpActionResult PosttblDocumento(tblDocumento tblDocumento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tblDocumento.Add(tblDocumento); try { db.SaveChanges(); } catch (DbUpdateException) { if (tblDocumentoExists(tblDocumento.id_Documento)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = tblDocumento.id_Documento }, tblDocumento)); }
public IHttpActionResult PuttblDocumento(int id, tblDocumento tblDocumento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblDocumento.id_Documento) { return(BadRequest()); } db.Entry(tblDocumento).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblDocumentoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GettblDocumento(int id) { tblDocumento tblDocumento = db.tblDocumento.Find(id); if (tblDocumento == null) { return(NotFound()); } return(Ok(tblDocumento)); }
public IHttpActionResult DeletetblDocumento(int id) { tblDocumento tblDocumento = db.tblDocumento.Find(id); if (tblDocumento == null) { return(NotFound()); } db.tblDocumento.Remove(tblDocumento); db.SaveChanges(); return(Ok(tblDocumento)); }
private string GetRouteFile(tblDocumento x) { eSystemModules Modulo = (eSystemModules)x.IdTipoDocumento; eEstadoDocumento EstadoDocumento = (eEstadoDocumento)x.IdEstadoDocumento; string _CodigoInforme = string.Format("{0}_{1}_{2}_{3}_{4}.{5}", Modulo.ToString(), x.IdEmpresa.ToString(), x.NroDocumento.ToString("#000"), (EstadoDocumento == eEstadoDocumento.Certificado ? x.FechaEstadoDocumento.ToString("MM-yyyy") : DateTime.Now.ToString("MM-yyyy")), x.VersionOriginal ?? 1, x.NroVersion); string _FileName = string.Format("{0}.pdf", _CodigoInforme.Replace("-", "_")); //string _pathFile = string.Format("https://www.BcmWeb_30.net/PDFDocs/{0}", _FileName); HttpServerUtility _Server = HttpContext.Current.Server; string _MapPath = _Server.MapPath("."); string _ServerPath = _MapPath.Substring(0, _MapPath.ToLowerInvariant().IndexOf("api")); string _pathFile = String.Format("{0}PDFDocs\\{1}", _ServerPath, _FileName); if (!File.Exists(_pathFile)) { _pathFile = string.Empty; } return(_pathFile); }
public static void RegistarAccion(eTipoAccion Accion) { long IdUser = long.Parse(Session["UserId"].ToString()); long IdEmpresa = long.Parse(Session["IdEmpresa"].ToString()); long IdDocumento = (Session["IdDocumento"] != null ? long.Parse(Session["IdDocumento"].ToString()) : 0); long IdTipoDocumento = (Session["IdTipoDocumento"] != null ? long.Parse(Session["IdTipoDocumento"].ToString()) : 0); long IdModuloActivo = (Session["modId"] != null ? long.Parse(Session["modId"].ToString()) : 0); long IdModuloPrincipal = IdTipoDocumento * 1000000; int IdClaseDocumento = (Session["IdClaseDocumento"] != null ? int.Parse(Session["IdClaseDocumento"].ToString()) : 0); string NombreAnexo = (Session["Anexo"] != null ? Session["Anexo"].ToString() : string.Empty); using (Entities db = new Entities()) { string AccionMessage = string.Empty; string NombreModulo = string.Empty; tblModulo moduloPrincipal = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == IdModuloPrincipal).FirstOrDefault(); tblModulo moduloActivo = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == IdModuloActivo).FirstOrDefault(); switch (Accion) { case eTipoAccion.AbrirDocumento: AccionMessage = Resources.AuditoriaResource.AbrirDocumentoMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.AbrirPDFMovil: AccionMessage = Resources.AuditoriaResource.AbrirPDFMovilMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.AbrirPDFWeb: AccionMessage = Resources.AuditoriaResource.AbrirPDFWebMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.AccesoModuloMovil: AccionMessage = Resources.AuditoriaResource.AccesoModuloMovilMessage; NombreModulo = moduloActivo.Nombre; break; case eTipoAccion.AccesoModuloWeb: AccionMessage = Resources.AuditoriaResource.AccesoModuloWebMessage; NombreModulo = moduloActivo.Nombre; break; case eTipoAccion.Actualizar: AccionMessage = Resources.AuditoriaResource.ActualizarAccionMessage; NombreModulo = moduloActivo.Nombre; break; case eTipoAccion.AprobarDocumento: AccionMessage = Resources.AuditoriaResource.AprobarDocumentoMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.CertificarDocumento: AccionMessage = Resources.AuditoriaResource.CertificarDocumentoMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.ConsultarCambios: AccionMessage = Resources.AuditoriaResource.ConsultarCambiosMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.Eliminar: AccionMessage = Resources.AuditoriaResource.EliminarAccionMessage; NombreModulo = moduloActivo.Nombre; break; case eTipoAccion.GenearCopiaDocumento: AccionMessage = Resources.AuditoriaResource.GenerarCopiaDocumentoMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.GenerarPDF: AccionMessage = Resources.AuditoriaResource.GenerarPDFMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.GenerarVersion: AccionMessage = Resources.AuditoriaResource.GenerarVersionMessage; NombreModulo = moduloPrincipal.Nombre; break; case eTipoAccion.Mostrar: AccionMessage = Resources.AuditoriaResource.MostrarAccionMessage; NombreModulo = moduloActivo.Nombre; break; case eTipoAccion.MostrarIniciativa: AccionMessage = Resources.AuditoriaResource.MostrarIniciativaMessage; NombreModulo = moduloActivo.Nombre; break; } tblUsuario usuario = db.tblUsuario.Where(x => x.IdUsuario == IdUser).FirstOrDefault(); tblDocumento Documento = db.tblDocumento.Where(x => x.IdEmpresa == IdEmpresa && x.IdDocumento == IdDocumento && x.IdTipoDocumento == IdTipoDocumento).FirstOrDefault(); string docVersion = string.Empty; string NroDocumento = string.Empty; string VersionActual = (Documento != null ? Documento.VersionOriginal.ToString() : string.Empty); if (Documento != null) { docVersion = (Documento.VersionOriginal > 0 ? string.Format("{0}.{1}", Documento.VersionOriginal, Documento.NroVersion) : Documento.NroVersion.ToString()); NroDocumento = Documento.NroDocumento.ToString(); } string _Accion = string.Format(AccionMessage, NombreModulo, NroDocumento, docVersion, NombreAnexo, VersionActual); tblAuditoria regAuditoria = new tblAuditoria { Accion = _Accion, DireccionIP = Request.UserHostAddress, FechaRegistro = DateTime.UtcNow, IdDocumento = IdDocumento, IdEmpresa = IdEmpresa, IdTipoDocumento = IdTipoDocumento, IdUsuario = IdUser, Mensaje = string.Empty, Negocios = (IdClaseDocumento == 1), }; db.tblAuditoria.Add(regAuditoria); usuario.FechaUltimaConexion = DateTime.UtcNow; usuario.EstadoUsuario = 2; db.SaveChanges(); } }
public static void RegistarOperacionAnexoModulo(string Operacion, string nombre, string viejo, bool Web = true) { string AccionMessage = string.Empty; string NombreModulo = string.Empty; long IdUser = long.Parse(Session["UserId"].ToString()); long IdEmpresa = long.Parse(Session["IdEmpresa"].ToString()); long IdDocumento = (Session["IdDocumento"] != null ? long.Parse(Session["IdDocumento"].ToString()) : 0); long IdTipoDocumento = (Session["IdTipoDocumento"] != null ? long.Parse(Session["IdTipoDocumento"].ToString()) : 0); long IdModuloActivo = (Session["modId"] != null ? long.Parse(Session["modId"].ToString()) : 0); long IdModuloPrincipal = IdTipoDocumento * 1000000; int IdClaseDocumento = (Session["IdClaseDocumento"] != null ? int.Parse(Session["IdClaseDocumento"].ToString()) : 0); long IdModulo = long.Parse(Session["IdModulo"].ToString()); NombreModulo = Metodos.GetNombreModulo(IdModulo); switch (Operacion) { case "FolderCreated": AccionMessage = Resources.AuditoriaResource.AnexoAgregarCarpetaModuloMessage; break; case "CurrentFolderChanged": break; case "FileDownloading": AccionMessage = Resources.AuditoriaResource.AnexoDescargarModuloWebMessage; break; case "FileUploaded": AccionMessage = Resources.AuditoriaResource.AnexoCargarModuloWebMessage; break; case "ItemCopied": AccionMessage = Resources.AuditoriaResource.AnexoCopiarItemModuloMessage; break; case "ItemDeleted": AccionMessage = Resources.AuditoriaResource.AnexoEliminarItemModuloMessage; break; case "ItemMoved": AccionMessage = Resources.AuditoriaResource.AnexoMoverItemModuloMessage; break; case "ItemRenamed": AccionMessage = Resources.AuditoriaResource.AnexoRenombrarItemModuloMessage; break; } using (Entities db = new Entities()) { if (!string.IsNullOrEmpty(AccionMessage)) { tblModulo moduloPrincipal = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == IdModuloPrincipal).FirstOrDefault(); tblModulo moduloActivo = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == IdModuloActivo).FirstOrDefault(); tblUsuario usuario = db.tblUsuario.Where(x => x.IdUsuario == IdUser).FirstOrDefault(); tblDocumento Documento = db.tblDocumento.Where(x => x.IdEmpresa == IdEmpresa && x.IdDocumento == IdDocumento && x.IdTipoDocumento == IdTipoDocumento).FirstOrDefault(); string docVersion = string.Empty; string NroDocumento = string.Empty; string VersionActual = (Documento != null ? Documento.VersionOriginal.ToString() : string.Empty); if (Documento != null) { docVersion = (Documento.VersionOriginal > 0 ? string.Format("{0}.{1}", Documento.VersionOriginal, Documento.NroVersion) : Documento.NroVersion.ToString()); NroDocumento = Documento.NroDocumento.ToString(); } string _Accion = string.Format(AccionMessage, NombreModulo, NroDocumento, docVersion, nombre, viejo); tblAuditoria regAuditoria = new tblAuditoria { Accion = _Accion, DireccionIP = Request.UserHostAddress, FechaRegistro = DateTime.UtcNow, IdDocumento = IdDocumento, IdEmpresa = IdEmpresa, IdTipoDocumento = IdTipoDocumento, IdUsuario = IdUser, Mensaje = string.Empty, Negocios = (IdClaseDocumento == 1), }; db.tblAuditoria.Add(regAuditoria); usuario.FechaUltimaConexion = DateTime.UtcNow; usuario.EstadoUsuario = 2; db.SaveChanges(); } } }
public string GenerarPDF_Documento(bool Mostrar) { _ServerPath = _Server.MapPath(".").Replace("\\Documentos", string.Empty); _tempFilePath = string.Format("{0}\\PDFDocs\\tempPDF", _ServerPath); _ImagenApliredPath = string.Format("{0}\\LogosEmpresa\\LogoAplired.png", _ServerPath); try { if (!Directory.Exists(_tempFilePath)) { Directory.CreateDirectory(_tempFilePath); } long IdDocumento = long.Parse(Session["IdDocumento"].ToString()); long IdEmpresa = long.Parse(Session["IdEmpresa"].ToString()); long IdUsuario = long.Parse(Session["UserId"].ToString()); long IdTipoDocumento = long.Parse(Session["IdTipoDocumento"].ToString()); eSystemModules Modulo = (eSystemModules)IdTipoDocumento; string TipoDocumento = Modulo.ToString(); string NombreModulo = string.Empty; if (GenerarArchivosTemporales()) { List <PdfReader> reader = new List <PdfReader>(); PdfImportedPage page; int rotation; int i = 0; int n = 0; _TableOfContent = new List <objContenido>(); _ActualPageWidth = PageSize.LETTER.Width; using (Entities db = new Entities()) { tblDocumento dataDocumento = (from d in db.tblDocumento where d.IdEmpresa == IdEmpresa && d.IdDocumento == IdDocumento && d.IdTipoDocumento == IdTipoDocumento select d).FirstOrDefault(); eEstadoDocumento EstadoDocumento = (eEstadoDocumento)dataDocumento.IdEstadoDocumento; //string _docPassowrd = string.Format("BCMWEB.{0}.{1}", (dataDocumento.Negocios ? "N" : "T"), IdEmpresa.ToString("000")); //string _ownerPassowrd = string.Format("{0}.{1}.{2}.BCMWEB", TipoDocumento, (dataDocumento.Negocios ? "N" : "T"), IdEmpresa.ToString("000")); string _CodigoInforme = string.Format("{0}_{1}_{2}_{3}_{4}.{5}", TipoDocumento, IdEmpresa.ToString(), dataDocumento.NroDocumento.ToString("#000"), (EstadoDocumento == eEstadoDocumento.Certificado ? dataDocumento.FechaEstadoDocumento.ToString("MM-yyyy") : DateTime.Now.ToString("MM-yyyy")), dataDocumento.VersionOriginal, dataDocumento.NroVersion); _FileName = string.Format("{0}.pdf", _CodigoInforme.Replace("-", "_")); _pathFile = String.Format("{0}\\PDFDocs\\{1}", _ServerPath, _FileName); _strDocURL = String.Format("{0}/PDFDocs/{1}", _AppUrl, _FileName); string _LogoEmpresaPath = string.Format("{0}{1}", _ServerPath, dataDocumento.tblEmpresa.LogoURL.Replace("/", "\\").Replace("~", "")); _ImagenEmpresa = Image.GetInstance(_LogoEmpresaPath); _ImagenEmpresa.Alignment = Element.ALIGN_CENTER; if (File.Exists(_pathFile)) { File.Delete(_pathFile); } string _pattern = string.Format("tmp{0}_{1}???_{2}*.pdf", TipoDocumento, IdEmpresa.ToString("000"), dataDocumento.IdDocumento.ToString("000")); List <string> _pdfFiles = Directory.GetFiles(_tempFilePath, _pattern, SearchOption.AllDirectories).OrderBy(q => q).ToList(); _Documento = new Document(); _pdfWrite = PdfWriter.GetInstance(_Documento, new FileStream(_pathFile, FileMode.Create)); _pdfWrite.PageEvent = _PDF_Events; //_pdfWrite.SetEncryption( // System.Text.Encoding.UTF8.GetBytes(_docPassowrd) // , System.Text.Encoding.UTF8.GetBytes(_ownerPassowrd) // , PdfWriter.AllowPrinting // , PdfWriter.ENCRYPTION_AES_256); string[] docKeywords = new string[] { _FileName, dataDocumento.tblEmpresa.NombreComercial, TipoDocumento, }; _Documento.Open(); _Documento.AddAuthor("www.bcmWeb.net"); _Documento.AddCreator("www.bcmweb.net"); _Documento.AddKeywords(string.Join(",", docKeywords)); int _PaginaInicioCapitulo = 1; foreach (string _fileName in _pdfFiles) { List <string> _fileSplit = _fileName.Split('_').ToList(); long _IdModulo = long.Parse(_fileSplit.Last().Split('.').First()); tblModulo dataModulo = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == _IdModulo).FirstOrDefault(); _TableOfContent.Add(new objContenido { Capitulo = dataModulo.Nombre, Indent = false, Page = _PaginaInicioCapitulo }); reader.Add(new PdfReader(_fileName)); i = 0; n = reader[reader.Count - 1].NumberOfPages; while (i < n) { i++; _Documento.SetPageSize(reader[reader.Count - 1].GetPageSizeWithRotation(i)); _Documento.NewPage(); page = _pdfWrite.GetImportedPage(reader[reader.Count - 1], i); PdfContentByte cb = _pdfWrite.DirectContent; rotation = reader[reader.Count - 1].GetPageRotation(i); if (rotation == 90 || rotation == 270) { cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader[reader.Count - 1].GetPageSizeWithRotation(i).Height); } else { cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0); } } _ActualPageWidth = PageSize.LETTER.Width; _PaginaInicioCapitulo += n; } long IdModuloPadre = IdTipoDocumento * 1000000; NombreModulo = db.tblModulo.Where(x => x.IdEmpresa == IdEmpresa && x.IdModulo == IdModuloPadre).FirstOrDefault().Nombre; GenerarIndice(NombreModulo); _Documento.Close(); foreach (PdfReader _reader in reader) { _reader.Close(); _reader.Dispose(); } if (Modulo == eSystemModules.PMI) { MoverDocumentosEscenarios(dataDocumento.Negocios, _CodigoInforme); } _pdfFiles = Directory.GetFiles(_tempFilePath, _pattern, SearchOption.AllDirectories).OrderBy(q => q).ToList(); foreach (string _fileName in _pdfFiles) { File.Delete(_fileName); } } } } catch (Exception ex) { //_Documento.Close(); throw ex; } return(_strDocURL); }
private bool GenerarArchivosTemporales() { bool Done = false; try { long IdDocumento = long.Parse(Session["IdDocumento"].ToString()); long IdEmpresa = long.Parse(Session["IdEmpresa"].ToString()); long IdUsuario = long.Parse(Session["UserId"].ToString()); long IdTipoDocumento = long.Parse(Session["IdTipoDocumento"].ToString()); eSystemModules Modulo = (eSystemModules)IdTipoDocumento; string TipoDocumento = Modulo.ToString(); tblDocumentoContenido _contenido; int _orden = 0; using (Entities db = new Entities()) { tblDocumento _dataDocumento = (from d in db.tblDocumento where d.IdEmpresa == IdEmpresa && d.IdDocumento == IdDocumento && d.IdTipoDocumento == IdTipoDocumento select d).FirstOrDefault(); if (_dataDocumento != null && _dataDocumento.tblDocumentoContenido != null) { switch (Modulo) { case eSystemModules.PAD: _orden++; _contenido = _dataDocumento.tblDocumentoContenido.Where(x => x.IdSubModulo == 10000101).FirstOrDefault(); if (_contenido != null) { GenerarPDF_Temporal(_contenido, TipoDocumento, _orden); } _orden++; _contenido = _dataDocumento.tblDocumentoContenido.Where(x => x.IdSubModulo == 10010200).FirstOrDefault(); if (_contenido != null) { GenerarPDF_Temporal(_contenido, TipoDocumento, _orden); } _orden++; _contenido = _dataDocumento.tblDocumentoContenido.Where(x => x.IdSubModulo == 10020100).FirstOrDefault(); if (_contenido != null) { GenerarPDF_Temporal(_contenido, TipoDocumento, _orden); } _orden++; _contenido = _dataDocumento.tblDocumentoContenido.Where(x => x.IdSubModulo == 10010300).FirstOrDefault(); if (_contenido != null) { GenerarPDF_Temporal(_contenido, TipoDocumento, _orden); } break; default: foreach (tblDocumentoContenido contenido in _dataDocumento.tblDocumentoContenido.OrderBy(x => x.IdSubModulo).ToList()) { _orden++; if (contenido.ContenidoBin != null && contenido.ContenidoBin.LongLength > 0) { GenerarPDF_Temporal(contenido, TipoDocumento, _orden); } } break; } } } Done = true; } catch { Done = false; throw; } return(Done); }