Compare commits
4 Commits
da4af4cb2a
...
fba8e12376
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fba8e12376 | ||
|
|
1c84a87f11 | ||
|
|
3c0b18f474 | ||
|
|
4e80ecca77 |
@@ -494,6 +494,7 @@ Rules:
|
||||
- Mandatory: read and follow `AGENTS_WEBFORMS_PARTIAL_POSTBACKS.md` for the single master form, ScriptManager ownership, UpdatePanel usage, and partial-postback rules.
|
||||
- Mandatory: read and follow `AGENTS_JAVASCRIPT_INITIALIZATION.md` for per-element initialization flags, global event guards, and idempotent control setup after partial postbacks.
|
||||
- Mandatory: read and follow `AGENTS_CATALOG_STRUCTURE.md` for catalog titles, breadcrumbs, actions, filters, indicators, grids, quick-create modals, and detail pages.
|
||||
- Mandatory: read and follow `AGENTS_DOCUMENT_STORAGE.md` for document folders, client access validation, protected file retrieval, and GIS file naming.
|
||||
- Keep stored procedure names centralized.
|
||||
- Repositories must use `CommandType.StoredProcedure` and parameterized inputs/outputs.
|
||||
- Never concatenate raw user input into SQL.
|
||||
|
||||
44
AGENTS_DOCUMENT_STORAGE.md
Normal file
44
AGENTS_DOCUMENT_STORAGE.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Reglas obligatorias para almacenamiento de documentos
|
||||
|
||||
Estas reglas complementan `AGENTS.md` y aplican a todo archivo persistido por la aplicación.
|
||||
|
||||
## Estructura física
|
||||
|
||||
La raíz de documentos de la aplicación es:
|
||||
|
||||
```text
|
||||
Documentos/
|
||||
Generales/
|
||||
Clientes/
|
||||
{CveCliente}/
|
||||
```
|
||||
|
||||
- `Generales` contiene documentos que no pertenecen a un cliente específico.
|
||||
- `Clientes` contiene una carpeta por `CveCliente`.
|
||||
- Antes de guardar un archivo, el servicio debe asegurar la existencia de `Documentos`, `Documentos/Generales`, `Documentos/Clientes` y de la carpeta específica del cliente cuando aplique.
|
||||
- No asumir que las carpetas ya existen. Usar una operación idempotente como `Directory.CreateDirectory` para crearlas cuando falten.
|
||||
- La misma regla aplica a futuras subcarpetas de documentos.
|
||||
|
||||
## Acceso y seguridad
|
||||
|
||||
- Las páginas WebForms y handlers no deben construir rutas físicas ni abrir archivos de cliente por su cuenta.
|
||||
- Todo guardado y obtención de archivos debe pasar por un servicio dedicado de documentos. Un handler de descarga sólo puede transmitir el archivo previamente autorizado y resuelto por ese servicio.
|
||||
- Antes de construir o abrir una ruta física, el servicio debe resolver en servidor el cliente propietario a partir de la entidad de negocio y validar el acceso del usuario.
|
||||
- No confiar para autorización en `CveCliente`, rutas físicas, rutas relativas ni nombres de archivo recibidos desde el navegador.
|
||||
- El rol `Empresa` se considera desarrollador y sólo puede acceder a documentos de clientes activos que tenga asignados en `Sis_UsuariosClientes`.
|
||||
- Los demás roles activos, incluidos `Administrador` y `SuperUsuario`, tienen acceso global a documentos, salvo que una regla funcional más restrictiva se defina explícitamente para un módulo.
|
||||
- Las rutas físicas bajo `Documentos` no deben exponerse como URLs públicas. Las descargas deben pasar por un endpoint autenticado que vuelva a validar el acceso mediante el servicio.
|
||||
|
||||
## GIS de etapas de fraccionamiento
|
||||
|
||||
- El botón `Agregar GIS` carga un archivo físico con extensión `.gis`; no solicita nombre ni URL de visualización al usuario.
|
||||
- El archivo se guarda en `Documentos/Clientes/{CveCliente}/`.
|
||||
- El nombre se genera exclusivamente en servidor con el formato:
|
||||
|
||||
```text
|
||||
gis-{CveFraccionamiento}-{CveFraccionamientoEtapa}.gis
|
||||
```
|
||||
|
||||
- El usuario no puede elegir ni modificar el nombre final del archivo.
|
||||
- Al reemplazar el GIS de una etapa se conserva el mismo nombre físico y se sobrescribe el archivo correspondiente.
|
||||
- La obtención del GIS debe usar el servicio de documentos y nunca una URL directa al folder `Documentos`.
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Configuration;
|
||||
using SIG.Web.AppCode.Contracts.Bitacora;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Documentos;
|
||||
using SIG.Web.AppCode.Contracts.Facturacion;
|
||||
using SIG.Web.AppCode.Contracts.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Contracts.General;
|
||||
@@ -13,6 +14,7 @@ using SIG.Web.AppCode.Notifications.Contracts;
|
||||
using SIG.Web.AppCode.Notifications.Services;
|
||||
using SIG.Web.AppCode.Repositories.Bitacora;
|
||||
using SIG.Web.AppCode.Repositories.Database;
|
||||
using SIG.Web.AppCode.Repositories.Documentos;
|
||||
using SIG.Web.AppCode.Repositories.Facturacion;
|
||||
using SIG.Web.AppCode.Repositories.General;
|
||||
using SIG.Web.AppCode.Repositories.Menu;
|
||||
@@ -20,6 +22,7 @@ using SIG.Web.AppCode.Repositories.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Repositories.Security;
|
||||
using SIG.Web.AppCode.Repositories.Tramites;
|
||||
using SIG.Web.AppCode.Services.Bitacora;
|
||||
using SIG.Web.AppCode.Services.Documentos;
|
||||
using SIG.Web.AppCode.Services.Facturacion;
|
||||
using SIG.Web.AppCode.Services.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Services.Menu;
|
||||
@@ -41,7 +44,9 @@ namespace SIG.Web.AppCode.Configuration
|
||||
private static IUserAdministrationRepository UserAdministrationRepository { get; set; }
|
||||
public static IUserAdministrationService UserAdministrationService { get; private set; }
|
||||
public static IGeneralCatalogRepository GeneralCatalogRepository { get; private set; }
|
||||
public static IClienteDocumentoService ClienteDocumentoService { get; private set; }
|
||||
public static IFraccionamientoService FraccionamientoService { get; private set; }
|
||||
public static IFraccionamientoGisService FraccionamientoGisService { get; private set; }
|
||||
public static ITramiteCatalogService TramiteCatalogService { get; private set; }
|
||||
public static ICfdiTimbradoService CfdiTimbradoService { get; private set; }
|
||||
public static IPublicRegistrationService PublicRegistrationService { get; private set; }
|
||||
@@ -83,9 +88,20 @@ namespace SIG.Web.AppCode.Configuration
|
||||
PasswordHasher,
|
||||
BitacoraService);
|
||||
GeneralCatalogRepository = new GeneralCatalogRepository(DbExecutor);
|
||||
ClienteDocumentoService = new ClienteDocumentoService(
|
||||
new ClienteDocumentoRepository(DbExecutor));
|
||||
FraccionamientoService = new FraccionamientoService(
|
||||
new FraccionamientoRepository(DbExecutor),
|
||||
BitacoraService);
|
||||
|
||||
IFraccionamientoGisRepository gisRepository =
|
||||
new FraccionamientoGisRepository(DbExecutor);
|
||||
IFraccionamientoGisFileStore gisFileStore =
|
||||
new FraccionamientoGisFileStore();
|
||||
FraccionamientoGisService = new FraccionamientoGisService(
|
||||
gisRepository,
|
||||
gisFileStore,
|
||||
BitacoraService);
|
||||
TramiteCatalogService = new TramiteCatalogService(
|
||||
new TramiteCatalogRepository(DbExecutor),
|
||||
BitacoraService);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Documentos;
|
||||
|
||||
namespace SIG.Web.AppCode.Contracts.Documentos
|
||||
{
|
||||
public interface IClienteDocumentoRepository
|
||||
{
|
||||
DbResult<ClienteDocumentoEtapaContextoModel> GetStageContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.IO;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Documentos;
|
||||
|
||||
namespace SIG.Web.AppCode.Contracts.Documentos
|
||||
{
|
||||
public interface IClienteDocumentoService
|
||||
{
|
||||
DbResult<ClienteDocumentoEtapaContextoModel> GetStageContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<ClienteDocumentoArchivoModel> SaveStageGis(
|
||||
int developmentId,
|
||||
int stageId,
|
||||
string originalFileName,
|
||||
Stream content,
|
||||
long contentLength,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<ClienteDocumentoArchivoModel> GetStageGis(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.IO;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
|
||||
namespace SIG.Web.AppCode.Contracts.Fraccionamientos
|
||||
{
|
||||
public interface IFraccionamientoGisFileStore
|
||||
{
|
||||
string GetPhysicalPath(FraccionamientoGisContextModel context);
|
||||
bool Exists(FraccionamientoGisContextModel context);
|
||||
void Save(FraccionamientoGisContextModel context, Stream source);
|
||||
Stream OpenRead(FraccionamientoGisContextModel context);
|
||||
void Delete(FraccionamientoGisContextModel context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
|
||||
namespace SIG.Web.AppCode.Contracts.Fraccionamientos
|
||||
{
|
||||
public interface IFraccionamientoGisRepository
|
||||
{
|
||||
DbResult<FraccionamientoGisContextModel> GetContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<List<FraccionamientoGisLotLinkModel>> ListLinks(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<bool> SaveLinks(
|
||||
int stageId,
|
||||
IList<FraccionamientoGisLotLinkModel> links,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<bool> ClearLinks(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
|
||||
namespace SIG.Web.AppCode.Contracts.Fraccionamientos
|
||||
{
|
||||
public interface IFraccionamientoGisService
|
||||
{
|
||||
DbResult<FraccionamientoGisViewModel> Get(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<FraccionamientoGisSaveResultModel> Save(
|
||||
int stageId,
|
||||
string originalFileName,
|
||||
Stream content,
|
||||
long contentLength,
|
||||
IList<FraccionamientoGisLotLinkModel> links,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<FraccionamientoGisSaveResultModel> Delete(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
|
||||
DbResult<FraccionamientoGisFileModel> OpenFile(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace SIG.Web.AppCode.Contracts.Fraccionamientos
|
||||
int executingUser,
|
||||
string domainName);
|
||||
DbResult<FraccionamientoEtapaGisModel> SaveStageGis(
|
||||
FraccionamientoEtapaGisModel gis,
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
DbResult<List<FraccionamientoEtapaTramiteModel>> ListStageProcedures(int developmentId, int executingUser, string domainName);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SIG.Web.AppCode.Contracts.Fraccionamientos
|
||||
int executingUser,
|
||||
string domainName);
|
||||
DbResult<FraccionamientoEtapaGisModel> SaveStageGis(
|
||||
FraccionamientoEtapaGisModel gis,
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName);
|
||||
DbResult<List<FraccionamientoEtapaTramiteModel>> ListStageProcedures(int developmentId, int executingUser, string domainName);
|
||||
|
||||
@@ -0,0 +1,435 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Web.SessionState;
|
||||
using SIG.Web.AppCode.Configuration;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Services.Errors;
|
||||
using SIG.Web.AppCode.Session;
|
||||
|
||||
namespace SIG.Web.Pages.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoGisHandler : IHttpHandler, IRequiresSessionState
|
||||
{
|
||||
private static readonly JavaScriptSerializer Json =
|
||||
new JavaScriptSerializer
|
||||
{
|
||||
MaxJsonLength = 4 * 1024 * 1024
|
||||
};
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
UserSessionModel currentUser = GetCurrentUser(context);
|
||||
if (currentUser == null)
|
||||
{
|
||||
WriteJson(
|
||||
context,
|
||||
401,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "Su sesión no está disponible. Inicie sesión nuevamente.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
string method = (context.Request["metodo"] ?? string.Empty)
|
||||
.Trim();
|
||||
|
||||
if (string.Equals(
|
||||
context.Request.HttpMethod,
|
||||
"POST",
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (string.Equals(method, "Save", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Save(context, currentUser);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.Equals(method, "Delete", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Delete(context, currentUser);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
405,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "La operación GIS solicitada no es válida.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
int stageId;
|
||||
if (!TryGetStageId(context, out stageId))
|
||||
{
|
||||
WriteJson(
|
||||
context,
|
||||
400,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "Seleccione una etapa válida.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.Equals(method, "Context", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
GetContext(context, currentUser, stageId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(method) ||
|
||||
string.Equals(method, "File", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
OpenFile(context, currentUser, stageId);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
405,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "La operación GIS solicitada no es válida.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteUnexpectedError(context, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static UserSessionModel GetCurrentUser(HttpContext context)
|
||||
{
|
||||
if (AppServices.UserContext == null ||
|
||||
!AppServices.UserContext.IsAuthenticated())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return AppServices.UserContext.GetCurrentUser();
|
||||
}
|
||||
|
||||
private static void GetContext(
|
||||
HttpContext context,
|
||||
UserSessionModel currentUser,
|
||||
int stageId)
|
||||
{
|
||||
DbResult<FraccionamientoGisViewModel> result =
|
||||
AppServices.FraccionamientoGisService.Get(
|
||||
stageId,
|
||||
currentUser.CveUsuario,
|
||||
currentUser.NombreDominio);
|
||||
|
||||
if (!result.Success || result.Data == null)
|
||||
{
|
||||
WriteResultFailure(context, result, 400);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
200,
|
||||
new
|
||||
{
|
||||
success = true,
|
||||
message = string.Empty,
|
||||
data = result.Data
|
||||
});
|
||||
}
|
||||
|
||||
private static void Save(
|
||||
HttpContext context,
|
||||
UserSessionModel currentUser)
|
||||
{
|
||||
int stageId;
|
||||
if (!TryGetStageId(context, out stageId))
|
||||
{
|
||||
WriteJson(
|
||||
context,
|
||||
400,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "Seleccione una etapa válida.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
IList<FraccionamientoGisLotLinkModel> links;
|
||||
string linksJson = context.Request.Form["vinculos"];
|
||||
|
||||
try
|
||||
{
|
||||
links = string.IsNullOrWhiteSpace(linksJson)
|
||||
? new List<FraccionamientoGisLotLinkModel>()
|
||||
: Json.Deserialize<List<FraccionamientoGisLotLinkModel>>(
|
||||
linksJson);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
WriteJson(
|
||||
context,
|
||||
400,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "Los vínculos GIS enviados no tienen un formato válido.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
HttpPostedFile postedFile = context.Request.Files["archivo"];
|
||||
Stream content = postedFile != null
|
||||
? postedFile.InputStream
|
||||
: null;
|
||||
long contentLength = postedFile != null
|
||||
? postedFile.ContentLength
|
||||
: 0L;
|
||||
string originalFileName = postedFile != null
|
||||
? Path.GetFileName(postedFile.FileName)
|
||||
: string.Empty;
|
||||
|
||||
DbResult<FraccionamientoGisSaveResultModel> result =
|
||||
AppServices.FraccionamientoGisService.Save(
|
||||
stageId,
|
||||
originalFileName,
|
||||
content,
|
||||
contentLength,
|
||||
links,
|
||||
currentUser.CveUsuario,
|
||||
currentUser.NombreDominio);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
WriteResultFailure(context, result, 400);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
200,
|
||||
new
|
||||
{
|
||||
success = true,
|
||||
message = "GIS y vínculos guardados correctamente.",
|
||||
data = result.Data
|
||||
});
|
||||
}
|
||||
|
||||
private static void Delete(
|
||||
HttpContext context,
|
||||
UserSessionModel currentUser)
|
||||
{
|
||||
int stageId;
|
||||
if (!TryGetStageId(context, out stageId))
|
||||
{
|
||||
WriteJson(
|
||||
context,
|
||||
400,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = "Seleccione una etapa válida.",
|
||||
codigo = string.Empty
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoGisSaveResultModel> result =
|
||||
AppServices.FraccionamientoGisService.Delete(
|
||||
stageId,
|
||||
currentUser.CveUsuario,
|
||||
currentUser.NombreDominio);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
WriteResultFailure(context, result, 400);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
200,
|
||||
new
|
||||
{
|
||||
success = true,
|
||||
message = "GIS eliminado y lotes desvinculados correctamente.",
|
||||
data = result.Data
|
||||
});
|
||||
}
|
||||
|
||||
private static void OpenFile(
|
||||
HttpContext context,
|
||||
UserSessionModel currentUser,
|
||||
int stageId)
|
||||
{
|
||||
DbResult<FraccionamientoGisFileModel> result =
|
||||
AppServices.FraccionamientoGisService.OpenFile(
|
||||
stageId,
|
||||
currentUser.CveUsuario,
|
||||
currentUser.NombreDominio);
|
||||
|
||||
if (!result.Success ||
|
||||
result.Data == null ||
|
||||
result.Data.Content == null)
|
||||
{
|
||||
WriteResultFailure(context, result, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
FraccionamientoGisFileModel file = result.Data;
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ClearHeaders();
|
||||
context.Response.TrySkipIisCustomErrors = true;
|
||||
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
||||
context.Response.Cache.SetNoStore();
|
||||
context.Response.ContentType = string.IsNullOrWhiteSpace(file.ContentType)
|
||||
? "application/octet-stream"
|
||||
: file.ContentType;
|
||||
|
||||
bool download = string.Equals(
|
||||
context.Request.QueryString["download"],
|
||||
"1",
|
||||
StringComparison.Ordinal);
|
||||
|
||||
context.Response.AddHeader(
|
||||
"Content-Disposition",
|
||||
(download ? "attachment" : "inline") +
|
||||
"; filename=\"" +
|
||||
SanitizeHeaderFileName(file.NombreArchivo) +
|
||||
"\"");
|
||||
|
||||
using (file.Content)
|
||||
{
|
||||
file.Content.CopyTo(context.Response.OutputStream);
|
||||
}
|
||||
|
||||
context.ApplicationInstance.CompleteRequest();
|
||||
}
|
||||
|
||||
private static bool TryGetStageId(
|
||||
HttpContext context,
|
||||
out int stageId)
|
||||
{
|
||||
string value = context.Request["CveFraccionamientoEtapa"];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
value = context.Request.QueryString["etapa"];
|
||||
}
|
||||
|
||||
return int.TryParse(
|
||||
value,
|
||||
NumberStyles.Integer,
|
||||
CultureInfo.InvariantCulture,
|
||||
out stageId) &&
|
||||
stageId > 0;
|
||||
}
|
||||
|
||||
private static void WriteResultFailure<T>(
|
||||
HttpContext context,
|
||||
DbResult<T> result,
|
||||
int statusCode)
|
||||
{
|
||||
string message = result == null ||
|
||||
string.IsNullOrWhiteSpace(result.UserMessage)
|
||||
? "No fue posible completar la operación GIS."
|
||||
: result.UserMessage;
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
statusCode,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = message,
|
||||
codigo = string.Empty
|
||||
});
|
||||
}
|
||||
|
||||
private static void WriteUnexpectedError(
|
||||
HttpContext context,
|
||||
Exception exception)
|
||||
{
|
||||
string cveUsuario;
|
||||
string nombreUsuario;
|
||||
int cveRol;
|
||||
|
||||
SIGErrorManager.ObtenerUsuarioActual(
|
||||
out cveUsuario,
|
||||
out nombreUsuario,
|
||||
out cveRol);
|
||||
|
||||
string code = SIGErrorManager.Registrar(
|
||||
exception,
|
||||
context,
|
||||
"FraccionamientoGisHandler",
|
||||
cveUsuario,
|
||||
nombreUsuario);
|
||||
|
||||
WriteJson(
|
||||
context,
|
||||
500,
|
||||
new
|
||||
{
|
||||
success = false,
|
||||
message = ErrorHandlerConfig.GetFriendlyMessage(exception),
|
||||
codigo = code
|
||||
});
|
||||
}
|
||||
|
||||
private static void WriteJson(
|
||||
HttpContext context,
|
||||
int statusCode,
|
||||
object value)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ClearHeaders();
|
||||
context.Response.StatusCode = statusCode;
|
||||
context.Response.TrySkipIisCustomErrors = true;
|
||||
context.Response.ContentType = "application/json; charset=utf-8";
|
||||
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
||||
context.Response.Cache.SetNoStore();
|
||||
context.Response.Write(Json.Serialize(value));
|
||||
context.ApplicationInstance.CompleteRequest();
|
||||
}
|
||||
|
||||
private static string SanitizeHeaderFileName(string fileName)
|
||||
{
|
||||
string safeName = string.IsNullOrWhiteSpace(fileName)
|
||||
? "archivo.gis"
|
||||
: Path.GetFileName(fileName);
|
||||
|
||||
return safeName
|
||||
.Replace("\"", string.Empty)
|
||||
.Replace("\r", string.Empty)
|
||||
.Replace("\n", string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
SIG.Web/App_Code/Models/Documentos/ClienteDocumentoModels.cs
Normal file
20
SIG.Web/App_Code/Models/Documentos/ClienteDocumentoModels.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace SIG.Web.AppCode.Models.Documentos
|
||||
{
|
||||
public sealed class ClienteDocumentoEtapaContextoModel
|
||||
{
|
||||
public int CveFraccionamientoEtapa { get; set; }
|
||||
public int CveFraccionamiento { get; set; }
|
||||
public int CveCliente { get; set; }
|
||||
public string Etapa { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ClienteDocumentoArchivoModel
|
||||
{
|
||||
public int CveCliente { get; set; }
|
||||
public int CveFraccionamiento { get; set; }
|
||||
public int CveFraccionamientoEtapa { get; set; }
|
||||
public string NombreArchivo { get; set; }
|
||||
public string RutaFisica { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace SIG.Web.AppCode.Models.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoGisContextModel
|
||||
{
|
||||
public int CveCliente { get; set; }
|
||||
public int CveFraccionamiento { get; set; }
|
||||
public int CveFraccionamientoEtapa { get; set; }
|
||||
public string Fraccionamiento { get; set; }
|
||||
public string Etapa { get; set; }
|
||||
}
|
||||
|
||||
public sealed class FraccionamientoGisLotLinkModel
|
||||
{
|
||||
public int CveFraccionamientoLote { get; set; }
|
||||
public string Nombre { get; set; }
|
||||
public string Etapa { get; set; }
|
||||
public string Numero { get; set; }
|
||||
public string Tipo { get; set; }
|
||||
public string Calle { get; set; }
|
||||
public string Catastro { get; set; }
|
||||
public decimal? MetrosCuadrados { get; set; }
|
||||
public string Duplicador { get; set; }
|
||||
public string GISPoligonoClave { get; set; }
|
||||
public bool EsActivo { get; set; }
|
||||
}
|
||||
|
||||
public sealed class FraccionamientoGisViewModel
|
||||
{
|
||||
public FraccionamientoGisContextModel Contexto { get; set; }
|
||||
public List<FraccionamientoGisLotLinkModel> Lotes { get; set; }
|
||||
public bool TieneArchivo { get; set; }
|
||||
public string NombreArchivo { get; set; }
|
||||
public DateTime? FechaArchivo { get; set; }
|
||||
}
|
||||
|
||||
public sealed class FraccionamientoGisSaveResultModel
|
||||
{
|
||||
public int CveFraccionamientoEtapa { get; set; }
|
||||
public int VinculosGuardados { get; set; }
|
||||
public bool ArchivoGuardado { get; set; }
|
||||
public bool TieneArchivo { get; set; }
|
||||
public string NombreArchivo { get; set; }
|
||||
public DateTime? FechaArchivo { get; set; }
|
||||
}
|
||||
|
||||
public sealed class FraccionamientoGisFileModel
|
||||
{
|
||||
public string NombreArchivo { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
public Stream Content { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,21 +13,20 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Bitacora
|
||||
{
|
||||
public sealed class BitacoraRepository : IBitacoraRepository
|
||||
public sealed class BitacoraRepository
|
||||
: RepositoryBase, IBitacoraRepository
|
||||
{
|
||||
private const string BitacoraDomain = "Bitacora";
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public BitacoraRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<long> Agregar(
|
||||
BitacoraEventoModel evento,
|
||||
BitacoraContextoModel contexto)
|
||||
{
|
||||
return _dbExecutor.Execute(BitacoraDomain, connection =>
|
||||
return ExecuteCustom(BitacoraDomain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
@@ -121,7 +120,7 @@ namespace SIG.Web.AppCode.Repositories.Bitacora
|
||||
BitacoraFiltroModel filtro,
|
||||
int cveUsuarioEjecuta)
|
||||
{
|
||||
return _dbExecutor.Execute(BitacoraDomain, connection =>
|
||||
return ExecuteCustom(BitacoraDomain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
@@ -181,7 +180,7 @@ namespace SIG.Web.AppCode.Repositories.Bitacora
|
||||
int registrosOmitidos = checked(
|
||||
(consulta.Pagina - 1) * consulta.RegistrosPorPagina);
|
||||
|
||||
return _dbExecutor.Execute(BitacoraDomain, connection =>
|
||||
return ExecuteCustom(BitacoraDomain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
@@ -275,7 +274,7 @@ namespace SIG.Web.AppCode.Repositories.Bitacora
|
||||
int registrosOmitidos = checked(
|
||||
(consulta.Pagina - 1) * consulta.RegistrosPorPagina);
|
||||
|
||||
return _dbExecutor.Execute(BitacoraDomain, connection =>
|
||||
return ExecuteCustom(BitacoraDomain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
|
||||
185
SIG.Web/App_Code/Repositories/Database/RepositoryBase.cs
Normal file
185
SIG.Web/App_Code/Repositories/Database/RepositoryBase.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Database
|
||||
{
|
||||
public abstract class RepositoryBase
|
||||
{
|
||||
private readonly IDbExecutor _db;
|
||||
|
||||
protected RepositoryBase(IDbExecutor db)
|
||||
{
|
||||
if (db == null)
|
||||
{
|
||||
throw new ArgumentNullException("db");
|
||||
}
|
||||
|
||||
_db = db;
|
||||
}
|
||||
|
||||
protected DbResult<TResult> ExecuteCustom<TResult>(
|
||||
string domain,
|
||||
Func<IDbConnection, TResult> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
return _db.Execute(domain, action);
|
||||
}
|
||||
|
||||
protected DbResult<TResult> QueryReader<TResult>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters,
|
||||
Func<IDataReader, TResult> readerMapper)
|
||||
{
|
||||
if (readerMapper == null)
|
||||
{
|
||||
throw new ArgumentNullException("readerMapper");
|
||||
}
|
||||
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
|
||||
TResult value;
|
||||
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = readerMapper(reader);
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected DbResult<List<T>> QueryList<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return QueryReader(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
parameters,
|
||||
reader => reader.ToList<T>());
|
||||
}
|
||||
|
||||
protected DbResult<T> QueryOne<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return QueryReader(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
parameters,
|
||||
reader => reader.ToObject<T>());
|
||||
}
|
||||
|
||||
protected DbResult<int> QueryScalarId(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return QueryReader(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
parameters,
|
||||
reader => reader.Read()
|
||||
? Convert.ToInt32(reader.GetValue(0))
|
||||
: 0);
|
||||
}
|
||||
|
||||
protected DbResult<long> QueryScalarLong(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return QueryReader(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
parameters,
|
||||
reader => reader.Read()
|
||||
? Convert.ToInt64(reader.GetValue(0))
|
||||
: 0L);
|
||||
}
|
||||
|
||||
protected DbResult<bool> QueryScalarBool(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
|
||||
object value = command.ExecuteScalar();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
|
||||
return value != null &&
|
||||
value != DBNull.Value &&
|
||||
Convert.ToBoolean(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected DbResult<bool> Execute(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Data;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Documentos;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Documentos;
|
||||
using SIG.Web.AppCode.Repositories.Database;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Documentos
|
||||
{
|
||||
public sealed class ClienteDocumentoRepository
|
||||
: RepositoryBase, IClienteDocumentoRepository
|
||||
{
|
||||
public ClienteDocumentoRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
}
|
||||
|
||||
public DbResult<ClienteDocumentoEtapaContextoModel> GetStageContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
return QueryOne<ClienteDocumentoEtapaContextoModel>(
|
||||
"dbo.PA_Fraccionamientos_EtapaDocumentoGet",
|
||||
executingUser,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,12 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Facturacion
|
||||
{
|
||||
public sealed class CfdiRepository : ICfdiRepository
|
||||
public sealed class CfdiRepository
|
||||
: RepositoryBase, ICfdiRepository
|
||||
{
|
||||
private readonly IDbExecutor _db;
|
||||
|
||||
public CfdiRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public DbResult<CfdiEmisorFiscalModel> ObtenerEmisor(
|
||||
@@ -442,94 +441,6 @@ namespace SIG.Web.AppCode.Repositories.Facturacion
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<List<T>> QueryList<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(
|
||||
command,
|
||||
procedure,
|
||||
user);
|
||||
parameters?.Invoke(command);
|
||||
|
||||
List<T> value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToList<T>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<T> QueryOne<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(
|
||||
command,
|
||||
procedure,
|
||||
user);
|
||||
parameters?.Invoke(command);
|
||||
|
||||
T value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToObject<T>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<long> QueryScalarLong(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(
|
||||
command,
|
||||
procedure,
|
||||
user);
|
||||
parameters(command);
|
||||
|
||||
long value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.Read()
|
||||
? Convert.ToInt64(reader.GetValue(0))
|
||||
: 0L;
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void Add(
|
||||
IDbCommand command,
|
||||
string name,
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Repositories.Database;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoGisRepository
|
||||
: RepositoryBase, IFraccionamientoGisRepository
|
||||
{
|
||||
public FraccionamientoGisRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoGisContextModel> GetContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
return QueryOne<FraccionamientoGisContextModel>(
|
||||
"dbo.PA_Fraccionamientos_EtapaGISContextGet",
|
||||
executingUser,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32));
|
||||
}
|
||||
|
||||
public DbResult<List<FraccionamientoGisLotLinkModel>> ListLinks(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
return QueryList<FraccionamientoGisLotLinkModel>(
|
||||
"dbo.PA_Fraccionamientos_EtapaGISVinculosGet",
|
||||
executingUser,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32));
|
||||
}
|
||||
|
||||
public DbResult<bool> SaveLinks(
|
||||
int stageId,
|
||||
IList<FraccionamientoGisLotLinkModel> links,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
IList<FraccionamientoGisLotLinkModel> safeLinks =
|
||||
links ?? new List<FraccionamientoGisLotLinkModel>();
|
||||
|
||||
XElement linksXml = new XElement(
|
||||
"Vinculos",
|
||||
safeLinks.Select(link =>
|
||||
new XElement(
|
||||
"Vinculo",
|
||||
new XAttribute(
|
||||
"CveFraccionamientoLote",
|
||||
link.CveFraccionamientoLote),
|
||||
new XAttribute(
|
||||
"GISPoligonoClave",
|
||||
link.GISPoligonoClave ?? string.Empty))));
|
||||
|
||||
return Execute(
|
||||
"dbo.PA_Fraccionamientos_EtapaGISVinculosSave",
|
||||
executingUser,
|
||||
domainName,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@VinculosXml",
|
||||
linksXml.ToString(SaveOptions.DisableFormatting),
|
||||
DbType.Xml);
|
||||
});
|
||||
}
|
||||
|
||||
public DbResult<bool> ClearLinks(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
return Execute(
|
||||
"dbo.PA_Fraccionamientos_EtapaGISVinculosClear",
|
||||
executingUser,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,12 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoRepository : IFraccionamientoRepository
|
||||
public sealed class FraccionamientoRepository
|
||||
: RepositoryBase, IFraccionamientoRepository
|
||||
{
|
||||
private readonly IDbExecutor _db;
|
||||
|
||||
public FraccionamientoRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public DbResult<List<FraccionamientoClienteOptionModel>> ListClients(int executingUser, string domainName)
|
||||
@@ -156,7 +155,7 @@ namespace SIG.Web.AppCode.Repositories.Fraccionamientos
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoEtapaGisModel> SaveStageGis(
|
||||
FraccionamientoEtapaGisModel gis,
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
@@ -164,24 +163,11 @@ namespace SIG.Web.AppCode.Repositories.Fraccionamientos
|
||||
"dbo.PA_Fraccionamientos_EtapaGISSave",
|
||||
executingUser,
|
||||
domainName,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
gis.CveFraccionamientoEtapa,
|
||||
DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@Nombre",
|
||||
gis.Nombre,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@UrlVisualizacion",
|
||||
gis.UrlVisualizacion,
|
||||
DbType.String);
|
||||
});
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveFraccionamientoEtapa",
|
||||
stageId,
|
||||
DbType.Int32));
|
||||
}
|
||||
|
||||
public DbResult<List<FraccionamientoEtapaTramiteModel>> ListStageProcedures(
|
||||
@@ -463,83 +449,5 @@ namespace SIG.Web.AppCode.Repositories.Fraccionamientos
|
||||
DbType.Int32);
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<List<T>> QueryList<T>(
|
||||
string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null) parameters(command);
|
||||
List<T> value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToList<T>();
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<T> QueryOne<T>(
|
||||
string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null) parameters(command);
|
||||
T value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToObject<T>();
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<int> QueryScalarId(
|
||||
string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
parameters(command);
|
||||
int value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.Read() ? Convert.ToInt32(reader.GetValue(0)) : 0;
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<bool> Execute(
|
||||
string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
parameters(command);
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,61 +9,49 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.General
|
||||
{
|
||||
public sealed class GeneralCatalogRepository : IGeneralCatalogRepository
|
||||
public sealed class GeneralCatalogRepository
|
||||
: RepositoryBase, IGeneralCatalogRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public GeneralCatalogRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<List<StateOptionModel>> ListStates(string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Gral_EstadoList", 0);
|
||||
|
||||
List<StateOptionModel> states;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
states = reader.ToList<StateOptionModel>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return states;
|
||||
}
|
||||
});
|
||||
return QueryList<StateOptionModel>(
|
||||
"dbo.PA_Gral_EstadoList",
|
||||
0,
|
||||
domainName,
|
||||
null);
|
||||
}
|
||||
|
||||
public DbResult<PostalCodeLookupModel> GetPostalCode(
|
||||
string postalCode,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
return QueryReader<PostalCodeLookupModel>(
|
||||
"dbo.PA_Gral_CodigoPostalGet",
|
||||
0,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CP",
|
||||
postalCode,
|
||||
DbType.String),
|
||||
reader =>
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Gral_CodigoPostalGet", 0);
|
||||
StoredProcedureCommand.AddInput(command, "@CP", postalCode, DbType.String);
|
||||
PostalCodeLookupModel value =
|
||||
reader.ToObject<PostalCodeLookupModel>();
|
||||
|
||||
PostalCodeLookupModel value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
if (value != null && reader.NextResult())
|
||||
{
|
||||
value = reader.ToObject<PostalCodeLookupModel>();
|
||||
|
||||
if (value != null && reader.NextResult())
|
||||
{
|
||||
value.Colonias = reader.ToList<NeighborhoodOptionModel>();
|
||||
}
|
||||
value.Colonias =
|
||||
reader.ToList<NeighborhoodOptionModel>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,50 +5,29 @@ using SIG.Web.AppCode.Contracts.Menu;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Repositories.Database;
|
||||
using SIG.Web.AppCode.Session;
|
||||
using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Menu
|
||||
{
|
||||
public sealed class MenuRepository : IMenuRepository
|
||||
public sealed class MenuRepository
|
||||
: RepositoryBase, IMenuRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public MenuRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<List<MenuItemModel>> ListModules(
|
||||
UserSessionModel user)
|
||||
{
|
||||
return _dbExecutor.Execute(
|
||||
return QueryList<MenuItemModel>(
|
||||
"dbo.PA_Sis_MenuList",
|
||||
user.CveUsuario,
|
||||
user.NombreDominio,
|
||||
connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(
|
||||
command,
|
||||
"dbo.PA_Sis_MenuList",
|
||||
user.CveUsuario);
|
||||
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveRol",
|
||||
user.CveRol,
|
||||
DbType.Int32);
|
||||
|
||||
List<MenuItemModel> items;
|
||||
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
items = reader.ToList<MenuItemModel>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return items;
|
||||
}
|
||||
});
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveRol",
|
||||
user.CveRol,
|
||||
DbType.Int32));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@ using SIG.Web.AppCode.Repositories.Database;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Security
|
||||
{
|
||||
public sealed class LoginAttemptRepository : ILoginAttemptRepository
|
||||
public sealed class LoginAttemptRepository
|
||||
: RepositoryBase, ILoginAttemptRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public LoginAttemptRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<bool> Save(
|
||||
@@ -24,24 +23,48 @@ namespace SIG.Web.AppCode.Repositories.Security
|
||||
string userAgent,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
return Execute(
|
||||
"dbo.PA_Sis_IntentoInicioSesionAdd",
|
||||
cveUser ?? 0,
|
||||
domainName,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Sis_IntentoInicioSesionAdd", cveUser ?? 0);
|
||||
StoredProcedureCommand.AddInput(command, "@CveUsuario", cveUser.HasValue ? (object)cveUser.Value : null, DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(command, "@NombreUsuario", username, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@Exitoso", wasSuccessful, DbType.Boolean);
|
||||
StoredProcedureCommand.AddInput(command, "@MotivoFallo", failureReason, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@DireccionIP", ipAddress, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@AgenteUsuario", userAgent, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@NombreDominio", domainName, DbType.String);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveUsuario",
|
||||
cveUser.HasValue ? (object)cveUser.Value : null,
|
||||
DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@NombreUsuario",
|
||||
username,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@Exitoso",
|
||||
wasSuccessful,
|
||||
DbType.Boolean);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@MotivoFallo",
|
||||
failureReason,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@DireccionIP",
|
||||
ipAddress,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@AgenteUsuario",
|
||||
userAgent,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@NombreDominio",
|
||||
domainName,
|
||||
DbType.String);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Security;
|
||||
@@ -7,22 +6,22 @@ using SIG.Web.AppCode.Repositories.Database;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Security
|
||||
{
|
||||
public sealed class PermissionRepository : IPermissionRepository
|
||||
public sealed class PermissionRepository
|
||||
: RepositoryBase, IPermissionRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public PermissionRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<bool> HasPermission(
|
||||
int cveUser,
|
||||
string permissionCode)
|
||||
{
|
||||
return ExecuteCheck(
|
||||
return QueryScalarBool(
|
||||
"dbo.PA_Sis_PermisoCheck",
|
||||
cveUser,
|
||||
null,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CodigoPermiso",
|
||||
@@ -34,40 +33,15 @@ namespace SIG.Web.AppCode.Repositories.Security
|
||||
int cveUser,
|
||||
string normalizedPageUrl)
|
||||
{
|
||||
return ExecuteCheck(
|
||||
return QueryScalarBool(
|
||||
"dbo.PA_Sis_PaginaAccessCheck",
|
||||
cveUser,
|
||||
null,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@PaginaUrl",
|
||||
normalizedPageUrl,
|
||||
DbType.String));
|
||||
}
|
||||
|
||||
private DbResult<bool> ExecuteCheck(
|
||||
string procedureName,
|
||||
int cveUser,
|
||||
Action<IDbCommand> addParameters)
|
||||
{
|
||||
return _dbExecutor.Execute(null, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(
|
||||
command,
|
||||
procedureName,
|
||||
cveUser);
|
||||
|
||||
addParameters(command);
|
||||
|
||||
object value = command.ExecuteScalar();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
|
||||
return value != null &&
|
||||
value != DBNull.Value &&
|
||||
Convert.ToBoolean(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Security
|
||||
{
|
||||
public sealed class UserAdministrationRepository : IUserAdministrationRepository
|
||||
public sealed class UserAdministrationRepository
|
||||
: RepositoryBase, IUserAdministrationRepository
|
||||
{
|
||||
private readonly IDbExecutor _db;
|
||||
public UserAdministrationRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public DbResult<List<UserAdministrationModel>> ListUsers(string text, int executingUser, string domainName)
|
||||
@@ -44,11 +44,12 @@ namespace SIG.Web.AppCode.Repositories.Security
|
||||
|
||||
public DbResult<int> SaveUser(UserAdministrationModel user, string passwordHash, int executingUser, string domainName)
|
||||
{
|
||||
return _db.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
return QueryScalarId(
|
||||
"dbo.PA_Sis_UsuarioSave",
|
||||
executingUser,
|
||||
domainName,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Sis_UsuarioSave", executingUser);
|
||||
StoredProcedureCommand.AddInput(command, "@CveUsuario", user.CveUsuario <= 0 ? (object)null : user.CveUsuario, DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(command, "@NombreUsuario", user.NombreUsuario, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@CorreoElectronico", user.CorreoElectronico, DbType.String);
|
||||
@@ -56,15 +57,7 @@ namespace SIG.Web.AppCode.Repositories.Security
|
||||
StoredProcedureCommand.AddInput(command, "@HashContrasena", passwordHash, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@Activo", user.Activo, DbType.Boolean);
|
||||
StoredProcedureCommand.AddInput(command, "@DebeCambiarContrasena", user.DebeCambiarContrasena, DbType.Boolean);
|
||||
int id;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
id = reader.Read() ? reader.GetInt32(0) : 0;
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return id;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public DbResult<bool> DeleteUser(int userId, int executingUser, string domainName)
|
||||
@@ -182,77 +175,5 @@ namespace SIG.Web.AppCode.Repositories.Security
|
||||
tokenHash,
|
||||
DbType.StringFixedLength));
|
||||
}
|
||||
|
||||
private DbResult<List<T>> QueryList<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
System.Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
List<T> value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToList<T>();
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<T> QueryOne<T>(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
System.Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
T value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToObject<T>();
|
||||
}
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<bool> Execute(string procedure, int user, string domain, System.Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,69 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using SIG.Web.AppCode.Contracts.Database;
|
||||
using SIG.Web.AppCode.Contracts.Security;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Security;
|
||||
using SIG.Web.AppCode.Repositories.Database;
|
||||
using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Security
|
||||
{
|
||||
public sealed class UserRepository : IUserRepository
|
||||
public sealed class UserRepository
|
||||
: RepositoryBase, IUserRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public UserRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<UserModel> ObtenerPorNombreUsuario(string username, string domainName)
|
||||
public DbResult<UserModel> ObtenerPorNombreUsuario(
|
||||
string username,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Sis_UsuarioGetByName", 0);
|
||||
StoredProcedureCommand.AddInput(command, "@NombreUsuario", username, DbType.String);
|
||||
|
||||
UserModel user;
|
||||
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
user = reader.ToObject<UserModel>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return user;
|
||||
}
|
||||
});
|
||||
return QueryOne<UserModel>(
|
||||
"dbo.PA_Sis_UsuarioGetByName",
|
||||
0,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@NombreUsuario",
|
||||
username,
|
||||
DbType.String));
|
||||
}
|
||||
|
||||
public DbResult<bool> RegisterSuccessfulLogin(int cveUser, string domainName)
|
||||
public DbResult<bool> RegisterSuccessfulLogin(
|
||||
int cveUser,
|
||||
string domainName)
|
||||
{
|
||||
return ExecuteUserUpdate("dbo.PA_Sis_UsuarioLoginSuccessUpdate", cveUser, domainName);
|
||||
return ExecuteUserUpdate(
|
||||
"dbo.PA_Sis_UsuarioLoginSuccessUpdate",
|
||||
cveUser,
|
||||
domainName);
|
||||
}
|
||||
|
||||
public DbResult<bool> RegisterFailedLogin(int cveUser, string domainName)
|
||||
public DbResult<bool> RegisterFailedLogin(
|
||||
int cveUser,
|
||||
string domainName)
|
||||
{
|
||||
return ExecuteUserUpdate("dbo.PA_Sis_UsuarioLoginFailedUpdate", cveUser, domainName);
|
||||
return ExecuteUserUpdate(
|
||||
"dbo.PA_Sis_UsuarioLoginFailedUpdate",
|
||||
cveUser,
|
||||
domainName);
|
||||
}
|
||||
|
||||
private DbResult<bool> ExecuteUserUpdate(string procedureName, int cveUser, string domainName)
|
||||
private DbResult<bool> ExecuteUserUpdate(
|
||||
string procedureName,
|
||||
int cveUser,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedureName, cveUser);
|
||||
StoredProcedureCommand.AddInput(command, "@CveUsuario", cveUser, DbType.Int32);
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return Execute(
|
||||
procedureName,
|
||||
cveUser,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveUsuario",
|
||||
cveUser,
|
||||
DbType.Int32));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,49 +6,68 @@ using SIG.Web.AppCode.Repositories.Database;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Security
|
||||
{
|
||||
public sealed class UserSessionRepository : IUserSessionRepository
|
||||
public sealed class UserSessionRepository
|
||||
: RepositoryBase, IUserSessionRepository
|
||||
{
|
||||
private readonly IDbExecutor _dbExecutor;
|
||||
|
||||
public UserSessionRepository(IDbExecutor dbExecutor)
|
||||
: base(dbExecutor)
|
||||
{
|
||||
_dbExecutor = dbExecutor;
|
||||
}
|
||||
|
||||
public DbResult<bool> StartSession(int cveUser, string sessionToken, string ipAddress, string userAgent, string domainName)
|
||||
public DbResult<bool> StartSession(
|
||||
int cveUser,
|
||||
string sessionToken,
|
||||
string ipAddress,
|
||||
string userAgent,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
return Execute(
|
||||
"dbo.PA_Sis_UsuarioSesionAdd",
|
||||
cveUser,
|
||||
domainName,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Sis_UsuarioSesionAdd", cveUser);
|
||||
StoredProcedureCommand.AddInput(command, "@CveUsuario", cveUser, DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(command, "@TokenSesion", sessionToken, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@DireccionIP", ipAddress, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@AgenteUsuario", userAgent, DbType.String);
|
||||
StoredProcedureCommand.AddInput(command, "@NombreDominio", domainName, DbType.String);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@CveUsuario",
|
||||
cveUser,
|
||||
DbType.Int32);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@TokenSesion",
|
||||
sessionToken,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@DireccionIP",
|
||||
ipAddress,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@AgenteUsuario",
|
||||
userAgent,
|
||||
DbType.String);
|
||||
StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@NombreDominio",
|
||||
domainName,
|
||||
DbType.String);
|
||||
});
|
||||
}
|
||||
|
||||
public DbResult<bool> EndSession(string sessionToken, string domainName)
|
||||
public DbResult<bool> EndSession(
|
||||
string sessionToken,
|
||||
string domainName)
|
||||
{
|
||||
return _dbExecutor.Execute(domainName, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Sis_UsuarioSesionEnd", 0);
|
||||
StoredProcedureCommand.AddInput(command, "@TokenSesion", sessionToken, DbType.String);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return Execute(
|
||||
"dbo.PA_Sis_UsuarioSesionEnd",
|
||||
0,
|
||||
domainName,
|
||||
command => StoredProcedureCommand.AddInput(
|
||||
command,
|
||||
"@TokenSesion",
|
||||
sessionToken,
|
||||
DbType.String));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,12 @@ using SIG.Web.AppCode.Utilities;
|
||||
|
||||
namespace SIG.Web.AppCode.Repositories.Tramites
|
||||
{
|
||||
public sealed class TramiteCatalogRepository : ITramiteCatalogRepository
|
||||
public sealed class TramiteCatalogRepository
|
||||
: RepositoryBase, ITramiteCatalogRepository
|
||||
{
|
||||
private readonly IDbExecutor _db;
|
||||
|
||||
public TramiteCatalogRepository(IDbExecutor db)
|
||||
: base(db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public DbResult<List<EstatusSolicitudModel>> ListEstatus(string texto, bool incluirInactivos, int usuario, string dominio)
|
||||
@@ -321,20 +320,17 @@ namespace SIG.Web.AppCode.Repositories.Tramites
|
||||
int usuario,
|
||||
string dominio)
|
||||
{
|
||||
return _db.Execute(dominio, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
return Execute(
|
||||
"dbo.PA_Tra_CatalogoOrdenMove",
|
||||
usuario,
|
||||
dominio,
|
||||
command =>
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, "dbo.PA_Tra_CatalogoOrdenMove", usuario);
|
||||
Add(command, "@Entidad", GetOrderEntityName(entity), DbType.String);
|
||||
Add(command, "@CveRegistro", id, DbType.Int32);
|
||||
Add(command, "@CveReferencia", referenceId, DbType.Int32);
|
||||
Add(command, "@ColocarDespues", placeAfter, DbType.Boolean);
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetOrderEntityName(TramiteCatalogOrderEntity entity)
|
||||
@@ -356,89 +352,35 @@ namespace SIG.Web.AppCode.Repositories.Tramites
|
||||
}
|
||||
}
|
||||
|
||||
private DbResult<List<T>> QueryList<T>(string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
private DbResult<int> Save(
|
||||
string procedure,
|
||||
int user,
|
||||
string domain,
|
||||
Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
if (parameters != null)
|
||||
{
|
||||
parameters(command);
|
||||
}
|
||||
|
||||
List<T> value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToList<T>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return QueryScalarId(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
parameters);
|
||||
}
|
||||
|
||||
private DbResult<T> QueryOne<T>(string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
where T : class, new()
|
||||
private DbResult<bool> Delete(
|
||||
string procedure,
|
||||
string parameterName,
|
||||
int id,
|
||||
int user,
|
||||
string domain)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
parameters(command);
|
||||
|
||||
T value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.ToObject<T>();
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<int> Save(string procedure, int user, string domain, Action<IDbCommand> parameters)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
parameters(command);
|
||||
|
||||
int value;
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
value = reader.Read()
|
||||
? Convert.ToInt32(reader.GetValue(0))
|
||||
: 0;
|
||||
}
|
||||
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DbResult<bool> Delete(string procedure, string parameterName, int id, int user, string domain)
|
||||
{
|
||||
return _db.Execute(domain, connection =>
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
StoredProcedureCommand.Configure(command, procedure, user);
|
||||
Add(command, parameterName, id, DbType.Int32);
|
||||
command.ExecuteNonQuery();
|
||||
StoredProcedureCommand.EnsureSuccess(command);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return Execute(
|
||||
procedure,
|
||||
user,
|
||||
domain,
|
||||
command => Add(
|
||||
command,
|
||||
parameterName,
|
||||
id,
|
||||
DbType.Int32));
|
||||
}
|
||||
|
||||
private static object NullableId(int value)
|
||||
|
||||
283
SIG.Web/App_Code/Services/Documentos/ClienteDocumentoService.cs
Normal file
283
SIG.Web/App_Code/Services/Documentos/ClienteDocumentoService.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using SIG.Web.AppCode.Contracts.Documentos;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Documentos;
|
||||
using SIG.Web.AppCode.Services.Logging;
|
||||
|
||||
namespace SIG.Web.AppCode.Services.Documentos
|
||||
{
|
||||
public sealed class ClienteDocumentoService : IClienteDocumentoService
|
||||
{
|
||||
private const string GisExtension = ".gis";
|
||||
private const string GisContentType = "application/octet-stream";
|
||||
|
||||
private readonly IClienteDocumentoRepository _repository;
|
||||
|
||||
public ClienteDocumentoService(IClienteDocumentoRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public DbResult<ClienteDocumentoEtapaContextoModel> GetStageContext(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<ClienteDocumentoEtapaContextoModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
return _repository.GetStageContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
}
|
||||
|
||||
public DbResult<ClienteDocumentoArchivoModel> SaveStageGis(
|
||||
int developmentId,
|
||||
int stageId,
|
||||
string originalFileName,
|
||||
Stream content,
|
||||
long contentLength,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (developmentId <= 0 || stageId <= 0)
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"Seleccione un fraccionamiento y una etapa válidos.");
|
||||
}
|
||||
|
||||
if (content == null || contentLength <= 0)
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"Seleccione un archivo GIS válido.");
|
||||
}
|
||||
|
||||
if (!string.Equals(
|
||||
Path.GetExtension(originalFileName),
|
||||
GisExtension,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"El archivo seleccionado debe tener extensión .gis.");
|
||||
}
|
||||
|
||||
DbResult<ClienteDocumentoEtapaContextoModel> contextResult =
|
||||
_repository.GetStageContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success)
|
||||
{
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Fail(
|
||||
contextResult.UserMessage,
|
||||
contextResult.TechnicalMessage,
|
||||
contextResult.Exception);
|
||||
}
|
||||
|
||||
ClienteDocumentoEtapaContextoModel stageContext =
|
||||
contextResult.Data;
|
||||
|
||||
if (stageContext == null ||
|
||||
stageContext.CveCliente <= 0 ||
|
||||
stageContext.CveFraccionamiento != developmentId ||
|
||||
stageContext.CveFraccionamientoEtapa != stageId)
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"La etapa no pertenece al fraccionamiento actual o no está disponible para el usuario.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string clientDirectory = EnsureClientDirectory(
|
||||
stageContext.CveCliente);
|
||||
string fileName = BuildStageGisFileName(stageContext);
|
||||
string physicalPath = Path.Combine(
|
||||
clientDirectory,
|
||||
fileName);
|
||||
|
||||
using (var fileStream = new FileStream(
|
||||
physicalPath,
|
||||
FileMode.Create,
|
||||
FileAccess.Write,
|
||||
FileShare.None))
|
||||
{
|
||||
content.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Ok(
|
||||
BuildFileModel(
|
||||
stageContext,
|
||||
fileName,
|
||||
physicalPath));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
const string userMessage =
|
||||
"No fue posible guardar el archivo GIS; favor de contactar a Sistemas.";
|
||||
ExceptionLogger.Log(
|
||||
ex,
|
||||
"ClienteDocumentoService.SaveStageGis",
|
||||
userMessage);
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Fail(
|
||||
userMessage,
|
||||
ex.Message,
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public DbResult<ClienteDocumentoArchivoModel> GetStageGis(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
DbResult<ClienteDocumentoEtapaContextoModel> contextResult =
|
||||
_repository.GetStageContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success)
|
||||
{
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Fail(
|
||||
contextResult.UserMessage,
|
||||
contextResult.TechnicalMessage,
|
||||
contextResult.Exception);
|
||||
}
|
||||
|
||||
ClienteDocumentoEtapaContextoModel stageContext =
|
||||
contextResult.Data;
|
||||
|
||||
if (stageContext == null ||
|
||||
stageContext.CveCliente <= 0 ||
|
||||
stageContext.CveFraccionamiento <= 0 ||
|
||||
stageContext.CveFraccionamientoEtapa != stageId)
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"La etapa no está disponible para el usuario actual.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string clientDirectory = BuildClientDirectory(
|
||||
stageContext.CveCliente);
|
||||
string fileName = BuildStageGisFileName(stageContext);
|
||||
string physicalPath = Path.Combine(
|
||||
clientDirectory,
|
||||
fileName);
|
||||
|
||||
if (!File.Exists(physicalPath))
|
||||
{
|
||||
return Fail<ClienteDocumentoArchivoModel>(
|
||||
"No se encontró el archivo GIS de la etapa.");
|
||||
}
|
||||
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Ok(
|
||||
BuildFileModel(
|
||||
stageContext,
|
||||
fileName,
|
||||
physicalPath));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
const string userMessage =
|
||||
"No fue posible obtener el archivo GIS; favor de contactar a Sistemas.";
|
||||
ExceptionLogger.Log(
|
||||
ex,
|
||||
"ClienteDocumentoService.GetStageGis",
|
||||
userMessage);
|
||||
return DbResult<ClienteDocumentoArchivoModel>.Fail(
|
||||
userMessage,
|
||||
ex.Message,
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static ClienteDocumentoArchivoModel BuildFileModel(
|
||||
ClienteDocumentoEtapaContextoModel stageContext,
|
||||
string fileName,
|
||||
string physicalPath)
|
||||
{
|
||||
return new ClienteDocumentoArchivoModel
|
||||
{
|
||||
CveCliente = stageContext.CveCliente,
|
||||
CveFraccionamiento = stageContext.CveFraccionamiento,
|
||||
CveFraccionamientoEtapa =
|
||||
stageContext.CveFraccionamientoEtapa,
|
||||
NombreArchivo = fileName,
|
||||
RutaFisica = physicalPath,
|
||||
ContentType = GisContentType
|
||||
};
|
||||
}
|
||||
|
||||
private static string BuildStageGisFileName(
|
||||
ClienteDocumentoEtapaContextoModel stageContext)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"gis-{0}-{1}.gis",
|
||||
stageContext.CveFraccionamiento,
|
||||
stageContext.CveFraccionamientoEtapa);
|
||||
}
|
||||
|
||||
private static string EnsureClientDirectory(int clientId)
|
||||
{
|
||||
string applicationRoot = GetApplicationRoot();
|
||||
string documentsDirectory = Path.Combine(
|
||||
applicationRoot,
|
||||
"Documentos");
|
||||
string generalDirectory = Path.Combine(
|
||||
documentsDirectory,
|
||||
"Generales");
|
||||
string clientsDirectory = Path.Combine(
|
||||
documentsDirectory,
|
||||
"Clientes");
|
||||
string clientDirectory = Path.Combine(
|
||||
clientsDirectory,
|
||||
clientId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
Directory.CreateDirectory(documentsDirectory);
|
||||
Directory.CreateDirectory(generalDirectory);
|
||||
Directory.CreateDirectory(clientsDirectory);
|
||||
Directory.CreateDirectory(clientDirectory);
|
||||
|
||||
return clientDirectory;
|
||||
}
|
||||
|
||||
private static string BuildClientDirectory(int clientId)
|
||||
{
|
||||
return Path.Combine(
|
||||
GetApplicationRoot(),
|
||||
"Documentos",
|
||||
"Clientes",
|
||||
clientId.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private static string GetApplicationRoot()
|
||||
{
|
||||
string applicationRoot = HttpRuntime.AppDomainAppPath;
|
||||
|
||||
return string.IsNullOrWhiteSpace(applicationRoot)
|
||||
? AppDomain.CurrentDomain.BaseDirectory
|
||||
: applicationRoot;
|
||||
}
|
||||
|
||||
private static DbResult<T> Fail<T>(string message)
|
||||
{
|
||||
return DbResult<T>.Fail(message, message, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,85 @@ namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
return auditEvent;
|
||||
}
|
||||
|
||||
public static BitacoraEventoModel CreateStageGisFileChange(
|
||||
FraccionamientoGisContextModel context,
|
||||
bool hadFile,
|
||||
bool fileUploaded,
|
||||
int previousLinkedLots,
|
||||
int currentLinkedLots)
|
||||
{
|
||||
string description;
|
||||
|
||||
if (!hadFile && fileUploaded)
|
||||
{
|
||||
description =
|
||||
"Se agregó el GIS de la etapa " + context.Etapa +
|
||||
". Se vincularon " + currentLinkedLots + " lotes.";
|
||||
}
|
||||
else if (hadFile && fileUploaded)
|
||||
{
|
||||
description =
|
||||
"Se reemplazó el GIS de la etapa " + context.Etapa +
|
||||
". Se desvincularon " + previousLinkedLots +
|
||||
" lotes y se vincularon " + currentLinkedLots +
|
||||
" lotes al nuevo GIS.";
|
||||
}
|
||||
else
|
||||
{
|
||||
description =
|
||||
"Se modificaron los vínculos GIS de la etapa " +
|
||||
context.Etapa + ". Vínculos anteriores: " +
|
||||
previousLinkedLots + "; vínculos actuales: " +
|
||||
currentLinkedLots + ".";
|
||||
}
|
||||
|
||||
return CreateStageGisFileEvent(
|
||||
context,
|
||||
BitacoraTipoMovimiento.Editado,
|
||||
description);
|
||||
}
|
||||
|
||||
public static BitacoraEventoModel CreateStageGisFileDelete(
|
||||
FraccionamientoGisContextModel context,
|
||||
int unlinkedLots)
|
||||
{
|
||||
return CreateStageGisFileEvent(
|
||||
context,
|
||||
BitacoraTipoMovimiento.Eliminado,
|
||||
"Se eliminó el GIS de la etapa " + context.Etapa +
|
||||
". Se desvincularon " + unlinkedLots + " lotes.");
|
||||
}
|
||||
|
||||
private static BitacoraEventoModel CreateStageGisFileEvent(
|
||||
FraccionamientoGisContextModel context,
|
||||
BitacoraTipoMovimiento movementType,
|
||||
string description)
|
||||
{
|
||||
var auditEvent = CreateEvent(
|
||||
"FraccionamientosEtapas",
|
||||
movementType,
|
||||
context.CveFraccionamientoEtapa,
|
||||
description,
|
||||
context.CveCliente);
|
||||
|
||||
auditEvent.Relaciones.Add(
|
||||
CreateRelation(
|
||||
BitacoraTipoRelacion.Directa,
|
||||
"FraccionamientosEtapas",
|
||||
"CveFraccionamientoEtapa",
|
||||
context.CveFraccionamientoEtapa,
|
||||
"Etapa del GIS."));
|
||||
auditEvent.Relaciones.Add(
|
||||
CreateRelation(
|
||||
BitacoraTipoRelacion.Relacionada,
|
||||
"Fraccionamientos",
|
||||
"CveFraccionamiento",
|
||||
context.CveFraccionamiento,
|
||||
"Fraccionamiento de la etapa."));
|
||||
|
||||
return auditEvent;
|
||||
}
|
||||
|
||||
public static BitacoraEventoModel CreateLot(
|
||||
FraccionamientoLoteModel previous,
|
||||
FraccionamientoLoteModel current,
|
||||
@@ -411,9 +490,16 @@ namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
|
||||
Uri uri;
|
||||
|
||||
return Uri.TryCreate(value, UriKind.Absolute, out uri)
|
||||
? uri.GetLeftPart(UriPartial.Path)
|
||||
: "[URL no válida]";
|
||||
if (Uri.TryCreate(value, UriKind.Absolute, out uri))
|
||||
{
|
||||
return uri.GetLeftPart(UriPartial.Path);
|
||||
}
|
||||
|
||||
int queryIndex = value.IndexOf('?');
|
||||
|
||||
return queryIndex >= 0
|
||||
? value.Substring(0, queryIndex)
|
||||
: value;
|
||||
}
|
||||
|
||||
private static IList<BitacoraCampoEventoModel> LotFields(
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web.Hosting;
|
||||
using SIG.Web.AppCode.Contracts.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
|
||||
namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoGisFileStore : IFraccionamientoGisFileStore
|
||||
{
|
||||
public string GetPhysicalPath(FraccionamientoGisContextModel context)
|
||||
{
|
||||
ValidateContext(context);
|
||||
|
||||
string relativeDirectory = string.Format(
|
||||
"~/Documentos/Clientes/{0}/",
|
||||
context.CveCliente);
|
||||
|
||||
string directory = HostingEnvironment.MapPath(relativeDirectory);
|
||||
if (string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"No fue posible resolver el directorio de documentos GIS.");
|
||||
}
|
||||
|
||||
return Path.Combine(
|
||||
directory,
|
||||
string.Format(
|
||||
"gis-{0}-{1}.gis",
|
||||
context.CveFraccionamiento,
|
||||
context.CveFraccionamientoEtapa));
|
||||
}
|
||||
|
||||
public bool Exists(FraccionamientoGisContextModel context)
|
||||
{
|
||||
return File.Exists(GetPhysicalPath(context));
|
||||
}
|
||||
|
||||
public void Save(FraccionamientoGisContextModel context, Stream source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
|
||||
string path = GetPhysicalPath(context);
|
||||
string directory = Path.GetDirectoryName(path);
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
string temporaryPath = Path.Combine(
|
||||
directory,
|
||||
"." + Path.GetFileName(path) + "." +
|
||||
Guid.NewGuid().ToString("N") + ".tmp");
|
||||
|
||||
try
|
||||
{
|
||||
if (source.CanSeek)
|
||||
{
|
||||
source.Position = 0;
|
||||
}
|
||||
|
||||
using (FileStream destination = new FileStream(
|
||||
temporaryPath,
|
||||
FileMode.CreateNew,
|
||||
FileAccess.Write,
|
||||
FileShare.None))
|
||||
{
|
||||
source.CopyTo(destination);
|
||||
destination.Flush();
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Replace(
|
||||
temporaryPath,
|
||||
path,
|
||||
null);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Move(
|
||||
temporaryPath,
|
||||
path);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(temporaryPath))
|
||||
{
|
||||
File.Delete(temporaryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Stream OpenRead(FraccionamientoGisContextModel context)
|
||||
{
|
||||
return new FileStream(
|
||||
GetPhysicalPath(context),
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
FileShare.Read);
|
||||
}
|
||||
|
||||
public void Delete(FraccionamientoGisContextModel context)
|
||||
{
|
||||
string path = GetPhysicalPath(context);
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateContext(FraccionamientoGisContextModel context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
|
||||
if (context.CveCliente <= 0 ||
|
||||
context.CveFraccionamiento <= 0 ||
|
||||
context.CveFraccionamientoEtapa <= 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"El contexto del archivo GIS no contiene claves válidas.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SIG.Web.AppCode.Contracts.Bitacora;
|
||||
using SIG.Web.AppCode.Contracts.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Infrastructure.Transactions;
|
||||
using SIG.Web.AppCode.Models.Bitacora;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Services.Logging;
|
||||
|
||||
namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
{
|
||||
public sealed class FraccionamientoGisService : IFraccionamientoGisService
|
||||
{
|
||||
private const string GisExtension = ".gis";
|
||||
private const string GisContentType = "application/json";
|
||||
private const long MaxFileSize = 30L * 1024L * 1024L;
|
||||
|
||||
private readonly IFraccionamientoGisRepository _repository;
|
||||
private readonly IFraccionamientoGisFileStore _fileStore;
|
||||
private readonly IBitacoraService _bitacoraService;
|
||||
|
||||
public FraccionamientoGisService(
|
||||
IFraccionamientoGisRepository repository,
|
||||
IFraccionamientoGisFileStore fileStore,
|
||||
IBitacoraService bitacoraService)
|
||||
{
|
||||
if (repository == null)
|
||||
{
|
||||
throw new ArgumentNullException("repository");
|
||||
}
|
||||
|
||||
if (fileStore == null)
|
||||
{
|
||||
throw new ArgumentNullException("fileStore");
|
||||
}
|
||||
|
||||
if (bitacoraService == null)
|
||||
{
|
||||
throw new ArgumentNullException("bitacoraService");
|
||||
}
|
||||
|
||||
_repository = repository;
|
||||
_fileStore = fileStore;
|
||||
_bitacoraService = bitacoraService;
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoGisViewModel> Get(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<FraccionamientoGisViewModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoGisContextModel> contextResult =
|
||||
_repository.GetContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success || contextResult.Data == null)
|
||||
{
|
||||
return CopyFailure<FraccionamientoGisContextModel, FraccionamientoGisViewModel>(
|
||||
contextResult,
|
||||
"No fue posible obtener el contexto GIS de la etapa.");
|
||||
}
|
||||
|
||||
DbResult<List<FraccionamientoGisLotLinkModel>> linksResult =
|
||||
_repository.ListLinks(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!linksResult.Success)
|
||||
{
|
||||
return CopyFailure<List<FraccionamientoGisLotLinkModel>, FraccionamientoGisViewModel>(
|
||||
linksResult,
|
||||
"No fue posible obtener los lotes de la etapa.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bool hasFile = _fileStore.Exists(contextResult.Data);
|
||||
|
||||
return DbResult<FraccionamientoGisViewModel>.Ok(
|
||||
new FraccionamientoGisViewModel
|
||||
{
|
||||
Contexto = contextResult.Data,
|
||||
Lotes = linksResult.Data ??
|
||||
new List<FraccionamientoGisLotLinkModel>(),
|
||||
TieneArchivo = hasFile,
|
||||
NombreArchivo = hasFile
|
||||
? Path.GetFileName(
|
||||
_fileStore.GetPhysicalPath(contextResult.Data))
|
||||
: string.Empty,
|
||||
FechaArchivo = hasFile
|
||||
? (DateTime?)File.GetLastWriteTime(
|
||||
_fileStore.GetPhysicalPath(contextResult.Data))
|
||||
: null
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
const string userMessage =
|
||||
"No fue posible consultar el archivo GIS; favor de contactar a Sistemas.";
|
||||
|
||||
ExceptionLogger.Log(
|
||||
ex,
|
||||
"FraccionamientoGisService.Get",
|
||||
userMessage);
|
||||
|
||||
return DbResult<FraccionamientoGisViewModel>.Fail(
|
||||
userMessage,
|
||||
ex.Message,
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoGisSaveResultModel> Save(
|
||||
int stageId,
|
||||
string originalFileName,
|
||||
Stream content,
|
||||
long contentLength,
|
||||
IList<FraccionamientoGisLotLinkModel> links,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
string validation = ValidateLinks(links);
|
||||
if (!string.IsNullOrWhiteSpace(validation))
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(validation);
|
||||
}
|
||||
|
||||
bool hasUploadedFile = content != null && contentLength > 0;
|
||||
|
||||
if (hasUploadedFile)
|
||||
{
|
||||
if (!string.Equals(
|
||||
Path.GetExtension(originalFileName),
|
||||
GisExtension,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"El archivo seleccionado debe tener extensión .gis.");
|
||||
}
|
||||
|
||||
if (contentLength > MaxFileSize)
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"El archivo GIS no puede exceder 30 MB.");
|
||||
}
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoGisContextModel> contextResult =
|
||||
_repository.GetContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success || contextResult.Data == null)
|
||||
{
|
||||
return CopyFailure<FraccionamientoGisContextModel, FraccionamientoGisSaveResultModel>(
|
||||
contextResult,
|
||||
"No fue posible obtener el contexto GIS de la etapa.");
|
||||
}
|
||||
|
||||
FraccionamientoGisContextModel gisContext = contextResult.Data;
|
||||
|
||||
DbResult<List<FraccionamientoGisLotLinkModel>> previousLinksResult =
|
||||
_repository.ListLinks(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!previousLinksResult.Success)
|
||||
{
|
||||
return CopyFailure<List<FraccionamientoGisLotLinkModel>, FraccionamientoGisSaveResultModel>(
|
||||
previousLinksResult,
|
||||
"No fue posible consultar los vínculos GIS actuales.");
|
||||
}
|
||||
|
||||
IList<FraccionamientoGisLotLinkModel> previousLinks =
|
||||
previousLinksResult.Data ??
|
||||
new List<FraccionamientoGisLotLinkModel>();
|
||||
|
||||
bool hadFile;
|
||||
|
||||
try
|
||||
{
|
||||
hadFile = _fileStore.Exists(gisContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FileFailure<FraccionamientoGisSaveResultModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.Save.Exists");
|
||||
}
|
||||
|
||||
if (!hasUploadedFile && !hadFile)
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"Seleccione un archivo .gis antes de guardar.");
|
||||
}
|
||||
|
||||
byte[] previousFile = null;
|
||||
|
||||
if (hasUploadedFile && hadFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (Stream previous = _fileStore.OpenRead(gisContext))
|
||||
using (var backup = new MemoryStream())
|
||||
{
|
||||
previous.CopyTo(backup);
|
||||
previousFile = backup.ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FileFailure<FraccionamientoGisSaveResultModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.Save.Backup");
|
||||
}
|
||||
}
|
||||
|
||||
bool fileWasWritten = false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var transaction = new TransactionLogic())
|
||||
{
|
||||
DbResult<bool> saveLinksResult =
|
||||
_repository.SaveLinks(
|
||||
stageId,
|
||||
links,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!saveLinksResult.Success)
|
||||
{
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Fail(
|
||||
saveLinksResult.UserMessage,
|
||||
saveLinksResult.TechnicalMessage,
|
||||
saveLinksResult.Exception);
|
||||
}
|
||||
|
||||
if (hasUploadedFile)
|
||||
{
|
||||
_fileStore.Save(gisContext, content);
|
||||
fileWasWritten = true;
|
||||
}
|
||||
|
||||
bool linksChanged = !LinksEqual(previousLinks, links);
|
||||
bool hasChange = hasUploadedFile || linksChanged;
|
||||
|
||||
if (hasChange)
|
||||
{
|
||||
BitacoraEventoModel auditEvent =
|
||||
FraccionamientoBitacoraFactory.CreateStageGisFileChange(
|
||||
gisContext,
|
||||
hadFile,
|
||||
hasUploadedFile,
|
||||
CountLinked(previousLinks),
|
||||
links.Count);
|
||||
|
||||
DbResult<long> auditResult =
|
||||
_bitacoraService.Registrar(auditEvent);
|
||||
|
||||
if (!auditResult.Success)
|
||||
{
|
||||
if (fileWasWritten)
|
||||
{
|
||||
RestorePreviousFile(
|
||||
gisContext,
|
||||
hadFile,
|
||||
previousFile);
|
||||
fileWasWritten = false;
|
||||
}
|
||||
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Fail(
|
||||
auditResult.UserMessage,
|
||||
auditResult.TechnicalMessage,
|
||||
auditResult.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
bool hasFile = _fileStore.Exists(gisContext);
|
||||
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Ok(
|
||||
new FraccionamientoGisSaveResultModel
|
||||
{
|
||||
CveFraccionamientoEtapa = stageId,
|
||||
VinculosGuardados = links.Count,
|
||||
ArchivoGuardado = hasUploadedFile,
|
||||
TieneArchivo = hasFile,
|
||||
NombreArchivo = hasFile
|
||||
? Path.GetFileName(
|
||||
_fileStore.GetPhysicalPath(gisContext))
|
||||
: string.Empty
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (fileWasWritten)
|
||||
{
|
||||
RestorePreviousFile(
|
||||
gisContext,
|
||||
hadFile,
|
||||
previousFile);
|
||||
}
|
||||
|
||||
return FileFailure<FraccionamientoGisSaveResultModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.Save");
|
||||
}
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoGisSaveResultModel> Delete(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoGisContextModel> contextResult =
|
||||
_repository.GetContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success || contextResult.Data == null)
|
||||
{
|
||||
return CopyFailure<FraccionamientoGisContextModel, FraccionamientoGisSaveResultModel>(
|
||||
contextResult,
|
||||
"No fue posible obtener el contexto GIS de la etapa.");
|
||||
}
|
||||
|
||||
DbResult<List<FraccionamientoGisLotLinkModel>> linksResult =
|
||||
_repository.ListLinks(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!linksResult.Success)
|
||||
{
|
||||
return CopyFailure<List<FraccionamientoGisLotLinkModel>, FraccionamientoGisSaveResultModel>(
|
||||
linksResult,
|
||||
"No fue posible consultar los vínculos GIS actuales.");
|
||||
}
|
||||
|
||||
FraccionamientoGisContextModel gisContext = contextResult.Data;
|
||||
IList<FraccionamientoGisLotLinkModel> previousLinks =
|
||||
linksResult.Data ?? new List<FraccionamientoGisLotLinkModel>();
|
||||
bool hadFile;
|
||||
byte[] previousFile = null;
|
||||
|
||||
try
|
||||
{
|
||||
hadFile = _fileStore.Exists(gisContext);
|
||||
|
||||
if (hadFile)
|
||||
{
|
||||
using (Stream previous = _fileStore.OpenRead(gisContext))
|
||||
using (var backup = new MemoryStream())
|
||||
{
|
||||
previous.CopyTo(backup);
|
||||
previousFile = backup.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FileFailure<FraccionamientoGisSaveResultModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.Delete.Backup");
|
||||
}
|
||||
|
||||
int linkedCount = CountLinked(previousLinks);
|
||||
|
||||
if (!hadFile && linkedCount == 0)
|
||||
{
|
||||
return Fail<FraccionamientoGisSaveResultModel>(
|
||||
"La etapa no tiene un GIS para eliminar.");
|
||||
}
|
||||
|
||||
bool fileWasDeleted = false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var transaction = new TransactionLogic())
|
||||
{
|
||||
DbResult<bool> clearResult =
|
||||
_repository.ClearLinks(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!clearResult.Success)
|
||||
{
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Fail(
|
||||
clearResult.UserMessage,
|
||||
clearResult.TechnicalMessage,
|
||||
clearResult.Exception);
|
||||
}
|
||||
|
||||
if (hadFile)
|
||||
{
|
||||
_fileStore.Delete(gisContext);
|
||||
fileWasDeleted = true;
|
||||
}
|
||||
|
||||
DbResult<long> auditResult =
|
||||
_bitacoraService.Registrar(
|
||||
FraccionamientoBitacoraFactory.CreateStageGisFileDelete(
|
||||
gisContext,
|
||||
linkedCount));
|
||||
|
||||
if (!auditResult.Success)
|
||||
{
|
||||
if (fileWasDeleted && previousFile != null)
|
||||
{
|
||||
using (var backup = new MemoryStream(previousFile, false))
|
||||
{
|
||||
_fileStore.Save(gisContext, backup);
|
||||
}
|
||||
fileWasDeleted = false;
|
||||
}
|
||||
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Fail(
|
||||
auditResult.UserMessage,
|
||||
auditResult.TechnicalMessage,
|
||||
auditResult.Exception);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
return DbResult<FraccionamientoGisSaveResultModel>.Ok(
|
||||
new FraccionamientoGisSaveResultModel
|
||||
{
|
||||
CveFraccionamientoEtapa = stageId,
|
||||
VinculosGuardados = 0,
|
||||
ArchivoGuardado = false,
|
||||
TieneArchivo = false,
|
||||
NombreArchivo = string.Empty,
|
||||
FechaArchivo = null
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (fileWasDeleted && previousFile != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var backup = new MemoryStream(previousFile, false))
|
||||
{
|
||||
_fileStore.Save(gisContext, backup);
|
||||
}
|
||||
}
|
||||
catch (Exception restoreException)
|
||||
{
|
||||
ExceptionLogger.Log(
|
||||
restoreException,
|
||||
"FraccionamientoGisService.Delete.Restore",
|
||||
"No fue posible restaurar el GIS después de un error al eliminarlo.");
|
||||
}
|
||||
}
|
||||
|
||||
return FileFailure<FraccionamientoGisSaveResultModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.Delete");
|
||||
}
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoGisFileModel> OpenFile(
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<FraccionamientoGisFileModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoGisContextModel> contextResult =
|
||||
_repository.GetContext(
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName);
|
||||
|
||||
if (!contextResult.Success || contextResult.Data == null)
|
||||
{
|
||||
return CopyFailure<FraccionamientoGisContextModel, FraccionamientoGisFileModel>(
|
||||
contextResult,
|
||||
"No fue posible obtener el contexto GIS de la etapa.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!_fileStore.Exists(contextResult.Data))
|
||||
{
|
||||
return Fail<FraccionamientoGisFileModel>(
|
||||
"No se encontró el archivo GIS de la etapa.");
|
||||
}
|
||||
|
||||
return DbResult<FraccionamientoGisFileModel>.Ok(
|
||||
new FraccionamientoGisFileModel
|
||||
{
|
||||
NombreArchivo = Path.GetFileName(
|
||||
_fileStore.GetPhysicalPath(contextResult.Data)),
|
||||
ContentType = GisContentType,
|
||||
Content = _fileStore.OpenRead(contextResult.Data)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FileFailure<FraccionamientoGisFileModel>(
|
||||
ex,
|
||||
"FraccionamientoGisService.OpenFile");
|
||||
}
|
||||
}
|
||||
|
||||
private void RestorePreviousFile(
|
||||
FraccionamientoGisContextModel context,
|
||||
bool hadFile,
|
||||
byte[] previousFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (hadFile && previousFile != null)
|
||||
{
|
||||
using (var backup = new MemoryStream(previousFile, false))
|
||||
{
|
||||
_fileStore.Save(context, backup);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileStore.Delete(context);
|
||||
}
|
||||
}
|
||||
catch (Exception restoreException)
|
||||
{
|
||||
ExceptionLogger.Log(
|
||||
restoreException,
|
||||
"FraccionamientoGisService.RestorePreviousFile",
|
||||
"No fue posible restaurar el archivo GIS después de un error.");
|
||||
}
|
||||
}
|
||||
|
||||
private static int CountLinked(
|
||||
IEnumerable<FraccionamientoGisLotLinkModel> links)
|
||||
{
|
||||
return links == null
|
||||
? 0
|
||||
: links.Count(link =>
|
||||
link != null &&
|
||||
link.CveFraccionamientoLote > 0 &&
|
||||
!string.IsNullOrWhiteSpace(link.GISPoligonoClave));
|
||||
}
|
||||
|
||||
private static bool LinksEqual(
|
||||
IEnumerable<FraccionamientoGisLotLinkModel> previous,
|
||||
IEnumerable<FraccionamientoGisLotLinkModel> current)
|
||||
{
|
||||
var previousMap = (previous ?? Enumerable.Empty<FraccionamientoGisLotLinkModel>())
|
||||
.Where(link =>
|
||||
link != null &&
|
||||
link.CveFraccionamientoLote > 0 &&
|
||||
!string.IsNullOrWhiteSpace(link.GISPoligonoClave))
|
||||
.ToDictionary(
|
||||
link => link.GISPoligonoClave.Trim(),
|
||||
link => link.CveFraccionamientoLote,
|
||||
StringComparer.Ordinal);
|
||||
|
||||
var currentMap = (current ?? Enumerable.Empty<FraccionamientoGisLotLinkModel>())
|
||||
.Where(link =>
|
||||
link != null &&
|
||||
link.CveFraccionamientoLote > 0 &&
|
||||
!string.IsNullOrWhiteSpace(link.GISPoligonoClave))
|
||||
.ToDictionary(
|
||||
link => link.GISPoligonoClave.Trim(),
|
||||
link => link.CveFraccionamientoLote,
|
||||
StringComparer.Ordinal);
|
||||
|
||||
return previousMap.Count == currentMap.Count &&
|
||||
previousMap.All(item =>
|
||||
{
|
||||
int lotId;
|
||||
return currentMap.TryGetValue(item.Key, out lotId) &&
|
||||
lotId == item.Value;
|
||||
});
|
||||
}
|
||||
|
||||
private static string ValidateLinks(
|
||||
IList<FraccionamientoGisLotLinkModel> links)
|
||||
{
|
||||
if (links == null || links.Count == 0)
|
||||
{
|
||||
return "Debe vincular los polígonos del GIS con los lotes antes de guardar.";
|
||||
}
|
||||
|
||||
var lotIds = new HashSet<int>();
|
||||
var polygonKeys = new HashSet<string>(StringComparer.Ordinal);
|
||||
|
||||
foreach (FraccionamientoGisLotLinkModel link in links)
|
||||
{
|
||||
if (link == null || link.CveFraccionamientoLote <= 0)
|
||||
{
|
||||
return "Existe un vínculo con un lote inválido.";
|
||||
}
|
||||
|
||||
string key = string.IsNullOrWhiteSpace(link.GISPoligonoClave)
|
||||
? null
|
||||
: link.GISPoligonoClave.Trim();
|
||||
|
||||
if (key == null)
|
||||
{
|
||||
return "Existe al menos un polígono sin una clave GIS válida.";
|
||||
}
|
||||
|
||||
if (key.Length > 100)
|
||||
{
|
||||
return "Una clave de polígono GIS excede 100 caracteres.";
|
||||
}
|
||||
|
||||
if (!lotIds.Add(link.CveFraccionamientoLote))
|
||||
{
|
||||
return "Un lote no puede vincularse con más de un polígono.";
|
||||
}
|
||||
|
||||
if (!polygonKeys.Add(key))
|
||||
{
|
||||
return "Un polígono no puede vincularse con más de un lote.";
|
||||
}
|
||||
|
||||
link.GISPoligonoClave = key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static DbResult<TTarget> CopyFailure<TSource, TTarget>(
|
||||
DbResult<TSource> source,
|
||||
string fallbackMessage)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
return Fail<TTarget>(fallbackMessage);
|
||||
}
|
||||
|
||||
return DbResult<TTarget>.Fail(
|
||||
string.IsNullOrWhiteSpace(source.UserMessage)
|
||||
? fallbackMessage
|
||||
: source.UserMessage,
|
||||
source.TechnicalMessage,
|
||||
source.Exception);
|
||||
}
|
||||
|
||||
private static DbResult<T> FileFailure<T>(
|
||||
Exception ex,
|
||||
string origin)
|
||||
{
|
||||
const string userMessage =
|
||||
"No fue posible procesar el archivo GIS; favor de contactar a Sistemas.";
|
||||
|
||||
ExceptionLogger.Log(
|
||||
ex,
|
||||
origin,
|
||||
userMessage);
|
||||
|
||||
return DbResult<T>.Fail(
|
||||
userMessage,
|
||||
ex.Message,
|
||||
ex);
|
||||
}
|
||||
|
||||
private static DbResult<T> Fail<T>(string message)
|
||||
{
|
||||
return DbResult<T>.Fail(
|
||||
message,
|
||||
message,
|
||||
null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,42 +224,19 @@ namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
}
|
||||
|
||||
public DbResult<FraccionamientoEtapaGisModel> SaveStageGis(
|
||||
FraccionamientoEtapaGisModel gis,
|
||||
int stageId,
|
||||
int executingUser,
|
||||
string domainName)
|
||||
{
|
||||
if (gis == null || gis.CveFraccionamientoEtapa <= 0)
|
||||
if (stageId <= 0)
|
||||
{
|
||||
return Fail<FraccionamientoEtapaGisModel>(
|
||||
"Seleccione una etapa válida.");
|
||||
}
|
||||
|
||||
gis.Nombre = TrimOrNull(gis.Nombre);
|
||||
gis.UrlVisualizacion = TrimOrNull(gis.UrlVisualizacion);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(gis.Nombre))
|
||||
{
|
||||
return Fail<FraccionamientoEtapaGisModel>(
|
||||
"Capture el nombre del GIS.");
|
||||
}
|
||||
|
||||
if (gis.Nombre.Length > 200)
|
||||
{
|
||||
return Fail<FraccionamientoEtapaGisModel>(
|
||||
"El nombre del GIS no puede exceder 200 caracteres.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(gis.UrlVisualizacion) ||
|
||||
gis.UrlVisualizacion.Length > 2000 ||
|
||||
!IsValidHttpUrl(gis.UrlVisualizacion))
|
||||
{
|
||||
return Fail<FraccionamientoEtapaGisModel>(
|
||||
"Capture una URL absoluta http o https válida para el GIS.");
|
||||
}
|
||||
|
||||
return ExecuteInTransaction(
|
||||
() => _repository.SaveStageGis(
|
||||
gis,
|
||||
stageId,
|
||||
executingUser,
|
||||
domainName),
|
||||
result => result.HuboCambio
|
||||
@@ -884,17 +861,6 @@ namespace SIG.Web.AppCode.Services.Fraccionamientos
|
||||
return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
}
|
||||
|
||||
private static bool IsValidHttpUrl(string value)
|
||||
{
|
||||
Uri uri;
|
||||
|
||||
return Uri.TryCreate(value, UriKind.Absolute, out uri) &&
|
||||
string.IsNullOrEmpty(uri.UserInfo) &&
|
||||
!string.IsNullOrWhiteSpace(uri.Host) &&
|
||||
(uri.Scheme == Uri.UriSchemeHttp ||
|
||||
uri.Scheme == Uri.UriSchemeHttps);
|
||||
}
|
||||
|
||||
private static DbResult<T> Fail<T>(string message)
|
||||
{
|
||||
return DbResult<T>.Fail(message, message, new ArgumentException(message));
|
||||
|
||||
412
SIG.Web/Documentos/Clientes/4/gis-5-7.gis
Normal file
412
SIG.Web/Documentos/Clientes/4/gis-5-7.gis
Normal file
@@ -0,0 +1,412 @@
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
"name": "Etapa1_10_lotes",
|
||||
"crs": {
|
||||
"type": "name",
|
||||
"properties": {
|
||||
"name": "EPSG:4326"
|
||||
}
|
||||
},
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-1",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 1",
|
||||
"Catastro": "CAT-001",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9555,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95532,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95532,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9555,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9555,
|
||||
29.09
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-2",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 1",
|
||||
"Catastro": "CAT-002",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9553,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95512,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95512,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9553,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9553,
|
||||
29.09
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-3",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 1",
|
||||
"Catastro": "CAT-003",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9551,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95492,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95492,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9551,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9551,
|
||||
29.09
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-4",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 1",
|
||||
"Catastro": "CAT-004",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9549,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95472,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95472,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9549,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9549,
|
||||
29.09
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-5",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 1",
|
||||
"Catastro": "CAT-005",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9547,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95452,
|
||||
29.09
|
||||
],
|
||||
[
|
||||
-110.95452,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9547,
|
||||
29.090139999999998
|
||||
],
|
||||
[
|
||||
-110.9547,
|
||||
29.09
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-6",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 2",
|
||||
"Catastro": "CAT-006",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9555,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95532,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95532,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9555,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9555,
|
||||
29.09016
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-7",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 2",
|
||||
"Catastro": "CAT-007",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9553,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95512,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95512,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9553,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9553,
|
||||
29.09016
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-8",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 2",
|
||||
"Catastro": "CAT-008",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9551,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95492,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95492,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9551,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9551,
|
||||
29.09016
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-9",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 2",
|
||||
"Catastro": "CAT-009",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9549,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95472,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95472,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9549,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9549,
|
||||
29.09016
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"Etapa": "Etapa 1",
|
||||
"Nombre": "Umbrella-10",
|
||||
"Tipo": "Lote",
|
||||
"Calle": "Calle Demo 2",
|
||||
"Catastro": "CAT-010",
|
||||
"MetrosCuadrados": 200.0,
|
||||
"Duplicador": 1,
|
||||
"Estatus": "Activa"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-110.9547,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95452,
|
||||
29.09016
|
||||
],
|
||||
[
|
||||
-110.95452,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9547,
|
||||
29.0903
|
||||
],
|
||||
[
|
||||
-110.9547,
|
||||
29.09016
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
0
SIG.Web/Documentos/Nuevo Documento de texto.txt
Normal file
0
SIG.Web/Documentos/Nuevo Documento de texto.txt
Normal file
@@ -12,6 +12,9 @@
|
||||
<link href='<%= ResolveUrl("~/Styles/CatalogosTramites.css") %>'
|
||||
rel="stylesheet"
|
||||
type="text/css" />
|
||||
<link href='<%= ResolveUrl("~/Styles/fraccionamiento-gis.css?v=20260818-2") %>'
|
||||
rel="stylesheet"
|
||||
type="text/css" />
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="ContentActions" ContentPlaceHolderID="A" runat="server">
|
||||
@@ -498,33 +501,11 @@
|
||||
|
||||
<asp:HyperLink ID="LnkStageGisOpen"
|
||||
runat="server"
|
||||
CssClass="btn btn-default btn-sm"
|
||||
Target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<i class="fa fa-external-link"></i>
|
||||
Abrir en otra pestaña
|
||||
CssClass="btn btn-default btn-sm">
|
||||
<i class="fa fa-download"></i>
|
||||
Descargar GIS
|
||||
</asp:HyperLink>
|
||||
</div>
|
||||
|
||||
<div class="fraction-gis-frame-wrap">
|
||||
<iframe id="IframeStageGis"
|
||||
runat="server"
|
||||
class="fraction-gis-frame js-sig-stage-gis-frame"
|
||||
title="GIS de la etapa seleccionada"
|
||||
loading="lazy"
|
||||
referrerpolicy="no-referrer"
|
||||
sandbox="allow-scripts allow-same-origin allow-forms allow-popups">
|
||||
</iframe>
|
||||
</div>
|
||||
</asp:Panel>
|
||||
|
||||
<asp:Panel ID="PnlStageGisInvalidUrl"
|
||||
runat="server"
|
||||
CssClass="alert alert-warning fraction-gis-warning"
|
||||
role="alert"
|
||||
Visible="false">
|
||||
El GIS guardado no tiene una URL HTTP/HTTPS válida.
|
||||
Use <strong>Administrar GIS</strong> para corregirla.
|
||||
</asp:Panel>
|
||||
|
||||
<div class="fraction-table-scroll fraction-lots-table">
|
||||
@@ -971,10 +952,12 @@
|
||||
|
||||
<div class="modal-body">
|
||||
<asp:Label ID="LblStageGisMessage"
|
||||
ClientIDMode="Static"
|
||||
runat="server"
|
||||
CssClass="alert alert-danger sig-modal-message sig-stage-gis-message"
|
||||
role="alert"
|
||||
Visible="false" />
|
||||
Visible="true"
|
||||
style="display:none;" />
|
||||
|
||||
<div class="fraction-selected-stage">
|
||||
<span>Etapa</span>
|
||||
@@ -984,49 +967,78 @@
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="TxtStageGisName">Nombre del GIS *</label>
|
||||
<asp:TextBox ID="TxtStageGisName"
|
||||
runat="server"
|
||||
ClientIDMode="Static"
|
||||
CssClass="form-control"
|
||||
MaxLength="200" />
|
||||
</div>
|
||||
<asp:HiddenField ID="HdStageGisId"
|
||||
ClientIDMode="Static"
|
||||
runat="server" />
|
||||
|
||||
<div class="form-group">
|
||||
<label for="TxtStageGisUrl">URL de visualización *</label>
|
||||
<asp:TextBox ID="TxtStageGisUrl"
|
||||
runat="server"
|
||||
ClientIDMode="Static"
|
||||
CssClass="form-control"
|
||||
TextMode="Url"
|
||||
MaxLength="2000"
|
||||
placeholder="https://..." />
|
||||
<span class="help-block">
|
||||
Utilice una dirección HTTP o HTTPS que permita mostrarse dentro de la plataforma.
|
||||
</span>
|
||||
<div class="sig-gis-layout">
|
||||
<div class="sig-gis-panel sig-gis-panel-files">
|
||||
<div class="form-group">
|
||||
<label>Archivo GIS</label>
|
||||
<input
|
||||
type="hidden"
|
||||
id="TxtGISLocal"
|
||||
class="ADSdropzoneLocal"
|
||||
data-maxFile="1"
|
||||
data-maxfilesize="30"
|
||||
data-acceptedfiles=".gis"
|
||||
data-message="Arrastra aquí un archivo .gis o haz clic para seleccionarlo." />
|
||||
<span class="help-block">
|
||||
El archivo permanece local hasta que presione Guardar GIS.
|
||||
Si ya existe un GIS puede conservarlo y modificar únicamente los vínculos.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div id="GisVinculosStatus"
|
||||
class="sig-gis-link-status"></div>
|
||||
|
||||
<div id="GisVinculos"
|
||||
class="sig-gis-links"></div>
|
||||
</div>
|
||||
|
||||
<div class="sig-gis-panel sig-gis-panel-map">
|
||||
<div id="MapGIS"
|
||||
class="sig-gis-map"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button"
|
||||
id="BtnDeleteStageGis"
|
||||
class="btn red"
|
||||
style="display:none;">
|
||||
<i class="fa fa-trash"></i>
|
||||
Eliminar GIS
|
||||
</button>
|
||||
|
||||
<button type="button"
|
||||
class="btn default"
|
||||
data-dismiss="modal">
|
||||
Cancelar
|
||||
</button>
|
||||
|
||||
<asp:Button ID="BtnSaveStageGis"
|
||||
<button type="button"
|
||||
id="BtnSaveStageGis"
|
||||
class="btn blue"
|
||||
disabled="disabled">
|
||||
<i class="fa fa-save"></i>
|
||||
Guardar GIS
|
||||
</button>
|
||||
|
||||
<asp:Button ID="BtnRefreshStageGis"
|
||||
ClientIDMode="Static"
|
||||
runat="server"
|
||||
CssClass="btn blue"
|
||||
Text="Guardar GIS"
|
||||
CssClass="hidden"
|
||||
CausesValidation="false"
|
||||
OnClick="BtnSaveStageGis_Click" />
|
||||
UseSubmitBehavior="false"
|
||||
OnClick="BtnRefreshStageGis_Click" />
|
||||
</div>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
<Triggers>
|
||||
<asp:AsyncPostBackTrigger
|
||||
ControlID="BtnSaveStageGis"
|
||||
ControlID="BtnRefreshStageGis"
|
||||
EventName="Click" />
|
||||
</Triggers>
|
||||
</asp:UpdatePanel>
|
||||
@@ -1311,38 +1323,25 @@
|
||||
<asp:Content ID="ContentScripts" ContentPlaceHolderID="J" runat="server">
|
||||
<script src='<%= ResolveUrl("~/Scripts/CatalogosTramites.js") %>'
|
||||
type="text/javascript"></script>
|
||||
<script src='<%= ResolveUrl("~/Scripts/fraccionamiento-gis.js?v=20260818-2") %>'
|
||||
type="text/javascript"></script>
|
||||
<script>
|
||||
window.SIGDetail = window.SIGDetail || {};
|
||||
|
||||
window.SIGDetail.initializeStageGisFrames = function (root) {
|
||||
var context = root || document;
|
||||
var frames = $(context)
|
||||
.find('.js-sig-stage-gis-frame:not([data-sig-stage-gis-initialized="1"])')
|
||||
.addBack('.js-sig-stage-gis-frame:not([data-sig-stage-gis-initialized="1"])');
|
||||
|
||||
frames.each(function () {
|
||||
var frame = this;
|
||||
var source = frame.getAttribute('data-src');
|
||||
var parser;
|
||||
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
parser = document.createElement('a');
|
||||
parser.href = source;
|
||||
|
||||
if (parser.protocol !== 'http:' && parser.protocol !== 'https:') {
|
||||
return;
|
||||
}
|
||||
|
||||
frame.setAttribute('src', source);
|
||||
frame.setAttribute('data-sig-stage-gis-initialized', '1');
|
||||
});
|
||||
window.FraccionamientoGISOptions = {
|
||||
modalId: 'ModalStageGis',
|
||||
stageInputId: 'HdStageGisId',
|
||||
fileInputId: 'TxtGISLocal',
|
||||
mapId: 'MapGIS',
|
||||
linksTableId: 'GisVinculos',
|
||||
statusId: 'GisVinculosStatus',
|
||||
saveButtonId: 'BtnSaveStageGis',
|
||||
deleteButtonId: 'BtnDeleteStageGis',
|
||||
refreshButtonId: 'BtnRefreshStageGis',
|
||||
handlerUrl: '<%= ResolveUrl("~/Pages/Fraccionamientos/FraccionamientoGis.ashx") %>'
|
||||
};
|
||||
|
||||
window.SIGDetail = window.SIGDetail || {};
|
||||
|
||||
window.SIGDetail.initialize = function (root) {
|
||||
window.SIGDetail.initializeStageGisFrames(root || document);
|
||||
};
|
||||
|
||||
window.SIGDetail.initializeModal = function (modalSelector) {
|
||||
|
||||
@@ -8,6 +8,7 @@ using SIG.Web.AppCode.Configuration;
|
||||
using SIG.Web.AppCode.Infrastructure.WebForms;
|
||||
using SIG.Web.AppCode.Models.Bitacora;
|
||||
using SIG.Web.AppCode.Models.Common;
|
||||
using SIG.Web.AppCode.Models.Documentos;
|
||||
using SIG.Web.AppCode.Models.Fraccionamientos;
|
||||
using SIG.Web.AppCode.Security;
|
||||
using SIG.Web.AppCode.Session;
|
||||
@@ -132,20 +133,6 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
}
|
||||
}
|
||||
|
||||
private int CveFraccionamientoEtapaGisRegistroActual
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveFraccionamientoEtapaGisRegistroActual"] == null
|
||||
? 0
|
||||
: (int)ViewState["CveFraccionamientoEtapaGisRegistroActual"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["CveFraccionamientoEtapaGisRegistroActual"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -463,87 +450,19 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
OpenStageGisModal();
|
||||
}
|
||||
|
||||
protected void BtnSaveStageGis_Click(
|
||||
protected void BtnRefreshStageGis_Click(
|
||||
object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
string safeUrl;
|
||||
|
||||
if (CveFraccionamientoEtapaGisActual <= 0)
|
||||
{
|
||||
ShowStageGisValidation(
|
||||
"Seleccione nuevamente la etapa del GIS.");
|
||||
return;
|
||||
}
|
||||
|
||||
string gisName = (TxtStageGisName.Text ?? string.Empty).Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(gisName))
|
||||
{
|
||||
ShowStageGisValidation("Capture el nombre del GIS.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gisName.Length > 200)
|
||||
{
|
||||
ShowStageGisValidation(
|
||||
"El nombre del GIS no puede exceder 200 caracteres.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryGetSafeVisualizationUrl(
|
||||
TxtStageGisUrl.Text,
|
||||
out safeUrl))
|
||||
{
|
||||
ShowStageGisValidation(
|
||||
"Capture una URL de visualización HTTP o HTTPS válida.");
|
||||
return;
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoEtapaModel> stageResult =
|
||||
AppServices.FraccionamientoService.GetStage(
|
||||
CveFraccionamientoEtapaGisActual,
|
||||
CurrentUser.CveUsuario,
|
||||
CurrentUser.NombreDominio);
|
||||
|
||||
if (!StageBelongsToCurrentDevelopment(stageResult))
|
||||
{
|
||||
ShowStageGisModal();
|
||||
Alert(
|
||||
GetStageValidationMessage(stageResult),
|
||||
GetStageValidationMessageType(stageResult));
|
||||
return;
|
||||
}
|
||||
|
||||
var gis = new FraccionamientoEtapaGisModel
|
||||
{
|
||||
CveFraccionamientoEtapaGIS =
|
||||
CveFraccionamientoEtapaGisRegistroActual,
|
||||
CveFraccionamientoEtapa =
|
||||
CveFraccionamientoEtapaGisActual,
|
||||
Nombre = gisName,
|
||||
UrlVisualizacion = safeUrl
|
||||
};
|
||||
|
||||
DbResult<FraccionamientoEtapaGisModel> result =
|
||||
AppServices.FraccionamientoService.SaveStageGis(
|
||||
gis,
|
||||
CurrentUser.CveUsuario,
|
||||
CurrentUser.NombreDominio);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
ShowStageGisModal();
|
||||
Alert(result.UserMessage, TipoMensaje.MsgError);
|
||||
return;
|
||||
}
|
||||
|
||||
HideStageGisMessage();
|
||||
BindSelectedStageLotsContext();
|
||||
UpDetailTabs.Update();
|
||||
HideStageGisModal();
|
||||
RefreshBitacoraDetalle();
|
||||
Alert("GIS guardado correctamente.", TipoMensaje.ToastExito);
|
||||
UpDetailTabs.Update();
|
||||
UpStageGisModal.Update();
|
||||
HideStageGisModal();
|
||||
Alert(
|
||||
"GIS actualizado correctamente.",
|
||||
TipoMensaje.ToastExito);
|
||||
}
|
||||
|
||||
protected void BtnClearStageLots_Click(
|
||||
@@ -1005,61 +924,45 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
return;
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoEtapaModel> stageResult =
|
||||
AppServices.FraccionamientoService.GetStage(
|
||||
DbResult<FraccionamientoGisViewModel> gisResult =
|
||||
AppServices.FraccionamientoGisService.Get(
|
||||
stageId,
|
||||
CurrentUser.CveUsuario,
|
||||
CurrentUser.NombreDominio);
|
||||
|
||||
if (!StageBelongsToCurrentDevelopment(stageResult))
|
||||
if (!gisResult.Success ||
|
||||
gisResult.Data == null ||
|
||||
gisResult.Data.Contexto == null)
|
||||
{
|
||||
Alert(
|
||||
GetStageValidationMessage(stageResult),
|
||||
GetStageValidationMessageType(stageResult));
|
||||
gisResult.Success
|
||||
? "No fue posible obtener el contexto GIS de la etapa."
|
||||
: gisResult.UserMessage,
|
||||
gisResult.Success
|
||||
? TipoMensaje.MsgAdvertencia
|
||||
: TipoMensaje.MsgError);
|
||||
return;
|
||||
}
|
||||
|
||||
DbResult<FraccionamientoEtapaGisModel> gisResult =
|
||||
AppServices.FraccionamientoService.GetStageGis(
|
||||
stageId,
|
||||
CurrentUser.CveUsuario,
|
||||
CurrentUser.NombreDominio);
|
||||
FraccionamientoGisViewModel gis = gisResult.Data;
|
||||
|
||||
if (!gisResult.Success)
|
||||
{
|
||||
Alert(gisResult.UserMessage, TipoMensaje.MsgError);
|
||||
return;
|
||||
}
|
||||
|
||||
FraccionamientoEtapaGisModel gis = gisResult.Data;
|
||||
|
||||
if (gis != null &&
|
||||
(gis.CveFraccionamientoEtapa != stageId ||
|
||||
gis.CveFraccionamiento != CveFraccionamientoActual))
|
||||
if (gis.Contexto.CveFraccionamiento != CveFraccionamientoActual)
|
||||
{
|
||||
Alert(
|
||||
"El GIS consultado no pertenece al fraccionamiento actual.",
|
||||
"La etapa no pertenece al fraccionamiento actual.",
|
||||
TipoMensaje.MsgAdvertencia);
|
||||
return;
|
||||
}
|
||||
|
||||
HideStageGisMessage();
|
||||
CveFraccionamientoEtapaGisActual = stageId;
|
||||
CveFraccionamientoEtapaGisRegistroActual = gis == null
|
||||
? 0
|
||||
: gis.CveFraccionamientoEtapaGIS;
|
||||
LitStageGisModalTitle.Text = gis == null
|
||||
? "Agregar GIS"
|
||||
: "Administrar GIS";
|
||||
HdStageGisId.Value = stageId.ToString(
|
||||
CultureInfo.InvariantCulture);
|
||||
LitStageGisModalTitle.Text = gis.TieneArchivo
|
||||
? "Administrar GIS"
|
||||
: "Agregar GIS";
|
||||
LitStageGisStageName.Text = EncodeDisplayValue(
|
||||
stageResult.Data.Etapa);
|
||||
TxtStageGisName.Text = gis == null
|
||||
? string.Empty
|
||||
: gis.Nombre;
|
||||
TxtStageGisUrl.Text = gis == null
|
||||
? string.Empty
|
||||
: gis.UrlVisualizacion;
|
||||
|
||||
gis.Contexto.Etapa);
|
||||
UpStageGisModal.Update();
|
||||
ShowStageGisModal();
|
||||
}
|
||||
@@ -1180,25 +1083,6 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
: TipoMensaje.MsgAdvertencia;
|
||||
}
|
||||
|
||||
private static bool TryGetSafeVisualizationUrl(
|
||||
string url,
|
||||
out string safeUrl)
|
||||
{
|
||||
safeUrl = null;
|
||||
Uri parsedUrl;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(url) ||
|
||||
!Uri.TryCreate(url.Trim(), UriKind.Absolute, out parsedUrl) ||
|
||||
(parsedUrl.Scheme != Uri.UriSchemeHttp &&
|
||||
parsedUrl.Scheme != Uri.UriSchemeHttps))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
safeUrl = parsedUrl.AbsoluteUri;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BindClients()
|
||||
{
|
||||
DbResult<List<FraccionamientoClienteOptionModel>> result =
|
||||
@@ -1507,14 +1391,10 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
PhStageGisMissing.Visible = false;
|
||||
PhStageGisExistingActions.Visible = false;
|
||||
PnlStageGisExisting.Visible = false;
|
||||
PnlStageGisInvalidUrl.Visible = false;
|
||||
LitStageGisName.Text = string.Empty;
|
||||
LitStageGisUpdatedAt.Text = string.Empty;
|
||||
LnkStageGisOpen.NavigateUrl = string.Empty;
|
||||
IframeStageGis.Attributes.Remove("src");
|
||||
IframeStageGis.Attributes.Remove("data-src");
|
||||
IframeStageGis.Attributes.Remove(
|
||||
"data-sig-stage-gis-initialized");
|
||||
HdStageGisId.Value = string.Empty;
|
||||
GvLots.DataSource = new List<FraccionamientoLoteModel>();
|
||||
GvLots.DataBind();
|
||||
}
|
||||
@@ -1524,37 +1404,33 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
PhStageGisMissing.Visible = false;
|
||||
PhStageGisExistingActions.Visible = false;
|
||||
PnlStageGisExisting.Visible = false;
|
||||
PnlStageGisInvalidUrl.Visible = false;
|
||||
LitStageGisName.Text = string.Empty;
|
||||
LitStageGisUpdatedAt.Text = string.Empty;
|
||||
LnkStageGisOpen.NavigateUrl = string.Empty;
|
||||
IframeStageGis.Attributes.Remove("src");
|
||||
IframeStageGis.Attributes.Remove("data-src");
|
||||
IframeStageGis.Attributes.Remove(
|
||||
"data-sig-stage-gis-initialized");
|
||||
|
||||
DbResult<FraccionamientoEtapaGisModel> result =
|
||||
AppServices.FraccionamientoService.GetStageGis(
|
||||
DbResult<FraccionamientoGisViewModel> result =
|
||||
AppServices.FraccionamientoGisService.Get(
|
||||
stageId,
|
||||
CurrentUser.CveUsuario,
|
||||
CurrentUser.NombreDominio);
|
||||
|
||||
if (!result.Success)
|
||||
if (!result.Success ||
|
||||
result.Data == null ||
|
||||
result.Data.Contexto == null)
|
||||
{
|
||||
Alert(result.UserMessage, TipoMensaje.MsgError);
|
||||
Alert(
|
||||
result.Success
|
||||
? "No fue posible obtener el contexto GIS de la etapa."
|
||||
: result.UserMessage,
|
||||
result.Success
|
||||
? TipoMensaje.MsgAdvertencia
|
||||
: TipoMensaje.MsgError);
|
||||
return;
|
||||
}
|
||||
|
||||
FraccionamientoEtapaGisModel gis = result.Data;
|
||||
FraccionamientoGisViewModel gis = result.Data;
|
||||
|
||||
if (gis == null)
|
||||
{
|
||||
PhStageGisMissing.Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (gis.CveFraccionamientoEtapa != stageId ||
|
||||
gis.CveFraccionamiento != CveFraccionamientoActual)
|
||||
if (gis.Contexto.CveFraccionamiento != CveFraccionamientoActual)
|
||||
{
|
||||
Alert(
|
||||
"El GIS consultado no pertenece al fraccionamiento actual.",
|
||||
@@ -1562,28 +1438,30 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
return;
|
||||
}
|
||||
|
||||
PhStageGisExistingActions.Visible = true;
|
||||
LitStageGisName.Text = EncodeDisplayValue(gis.Nombre);
|
||||
|
||||
DateTime updatedAt = gis.FechaModificacion ?? gis.FechaAlta;
|
||||
LitStageGisUpdatedAt.Text = Server.HtmlEncode(
|
||||
"Actualizado " + updatedAt.ToString(
|
||||
"dd/MM/yyyy HH:mm",
|
||||
CultureInfo.CurrentCulture));
|
||||
|
||||
string safeUrl;
|
||||
|
||||
if (!TryGetSafeVisualizationUrl(
|
||||
gis.UrlVisualizacion,
|
||||
out safeUrl))
|
||||
if (!gis.TieneArchivo)
|
||||
{
|
||||
PnlStageGisInvalidUrl.Visible = true;
|
||||
PhStageGisMissing.Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
PhStageGisExistingActions.Visible = true;
|
||||
LitStageGisName.Text = EncodeDisplayValue(
|
||||
gis.NombreArchivo);
|
||||
|
||||
if (gis.FechaArchivo.HasValue)
|
||||
{
|
||||
LitStageGisUpdatedAt.Text = Server.HtmlEncode(
|
||||
"Actualizado " + gis.FechaArchivo.Value.ToString(
|
||||
"dd/MM/yyyy HH:mm",
|
||||
CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
PnlStageGisExisting.Visible = true;
|
||||
LnkStageGisOpen.NavigateUrl = safeUrl;
|
||||
IframeStageGis.Attributes["data-src"] = safeUrl;
|
||||
LnkStageGisOpen.NavigateUrl = ResolveUrl(
|
||||
"~/Pages/Fraccionamientos/FraccionamientoGis.ashx" +
|
||||
"?metodo=File&etapa=" +
|
||||
stageId.ToString(CultureInfo.InvariantCulture) +
|
||||
"&download=1");
|
||||
}
|
||||
|
||||
private void EditLot(int lotId)
|
||||
@@ -1998,13 +1876,15 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
LblStageGisMessage.Text = Server.HtmlEncode(
|
||||
message ?? string.Empty);
|
||||
LblStageGisMessage.Visible = true;
|
||||
LblStageGisMessage.Style["display"] = "block";
|
||||
UpStageGisModal.Update();
|
||||
ShowStageGisModal();
|
||||
}
|
||||
|
||||
private void HideStageGisMessage()
|
||||
{
|
||||
LblStageGisMessage.Visible = false;
|
||||
LblStageGisMessage.Visible = true;
|
||||
LblStageGisMessage.Style["display"] = "none";
|
||||
LblStageGisMessage.Text = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,16 +310,6 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.WebControls.HyperLink LnkStageGisOpen;
|
||||
|
||||
/// <summary>
|
||||
/// IframeStageGis control.
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlGenericControl IframeStageGis;
|
||||
|
||||
/// <summary>
|
||||
/// PnlStageGisInvalidUrl control.
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.WebControls.Panel PnlStageGisInvalidUrl;
|
||||
|
||||
/// <summary>
|
||||
/// GvLots control.
|
||||
/// </summary>
|
||||
@@ -569,19 +559,14 @@ namespace SIG.Web.Pages.Fraccionamientos
|
||||
protected global::System.Web.UI.WebControls.Literal LitStageGisStageName;
|
||||
|
||||
/// <summary>
|
||||
/// TxtStageGisName control.
|
||||
/// HdStageGisId control.
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.WebControls.TextBox TxtStageGisName;
|
||||
protected global::System.Web.UI.WebControls.HiddenField HdStageGisId;
|
||||
|
||||
/// <summary>
|
||||
/// TxtStageGisUrl control.
|
||||
/// BtnRefreshStageGis control.
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.WebControls.TextBox TxtStageGisUrl;
|
||||
|
||||
/// <summary>
|
||||
/// BtnSaveStageGis control.
|
||||
/// </summary>
|
||||
protected global::System.Web.UI.WebControls.Button BtnSaveStageGis;
|
||||
protected global::System.Web.UI.WebControls.Button BtnRefreshStageGis;
|
||||
|
||||
/// <summary>
|
||||
/// UpLotsModal control.
|
||||
|
||||
1
SIG.Web/Pages/Fraccionamientos/FraccionamientoGis.ashx
Normal file
1
SIG.Web/Pages/Fraccionamientos/FraccionamientoGis.ashx
Normal file
@@ -0,0 +1 @@
|
||||
<%@ WebHandler Language="C#" Class="SIG.Web.Pages.Fraccionamientos.FraccionamientoGisHandler" %>
|
||||
@@ -130,6 +130,7 @@
|
||||
<Content Include="Pages\Fraccionamientos\Fraccionamientos.aspx" />
|
||||
<Content Include="Pages\Fraccionamientos\FraccionamientoDetalle.aspx" />
|
||||
<Content Include="Pages\Fraccionamientos\PlantillaLotes.ashx" />
|
||||
<Content Include="Pages\Fraccionamientos\FraccionamientoGis.ashx" />
|
||||
<Content Include="Site.master" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="adssw.js" Condition="Exists('adssw.js')" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* custom.js
|
||||
* Cleaned for the new C# WebForms project.
|
||||
* Notes:
|
||||
@@ -1460,7 +1460,7 @@ function ADDropzone(txtid) {
|
||||
//initialize variables
|
||||
//var txt;
|
||||
var domain = window.location.origin;
|
||||
this.txt = $('#' + txtid); if (txt.val() == '') { txt.val('[]'); }
|
||||
var txt = $('#' + txtid); if (txt.val() == '') { txt.val('[]'); }
|
||||
if (txt.data('loaded') == '1') { }
|
||||
|
||||
else {
|
||||
@@ -1606,6 +1606,356 @@ function loadAdDropzone() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function ADDropzoneLocal(txtid) {
|
||||
var txt = $('#' + txtid);
|
||||
|
||||
if (!txt.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (txt.attr('data-sig-dropzone-local-initialized') === '1') {
|
||||
return window.ADSLocalDropzone
|
||||
? window.ADSLocalDropzone.instance(txtid)
|
||||
: null;
|
||||
}
|
||||
|
||||
var maxFilesize = Number(txt.attr('data-maxfilesize')) || 30;
|
||||
var maxFile = parseInt(
|
||||
txt.attr('data-maxFile') || txt.attr('data-maxfile'),
|
||||
10);
|
||||
var acceptedFiles = txt.attr('data-acceptedfiles') || null;
|
||||
var message = txt.attr('data-message') ||
|
||||
'Arrastra un archivo aquí o haz clic para seleccionarlo.';
|
||||
var appendId = txt.attr('data-append');
|
||||
var dropId = txtid + '-drop';
|
||||
var existing = $('#' + dropId);
|
||||
|
||||
if (existing.length) {
|
||||
existing.remove();
|
||||
}
|
||||
|
||||
var mydiv = $(
|
||||
'<div id="' + dropId + '" class="addropzone ADSdropzoneLocalContainer" tabindex="0">' +
|
||||
' <div class="dz-message">' + $('<div/>').text(message).html() + '</div>' +
|
||||
'</div>');
|
||||
|
||||
if (appendId && $('#' + appendId).length) {
|
||||
$('#' + appendId).empty().append(mydiv);
|
||||
} else {
|
||||
txt.after(mydiv);
|
||||
}
|
||||
|
||||
function registerInstance(instance) {
|
||||
txt.attr('data-sig-dropzone-local-initialized', '1');
|
||||
window.ADSLocalDropzone = window.ADSLocalDropzone || {};
|
||||
window.ADSLocalDropzone.instances =
|
||||
window.ADSLocalDropzone.instances || {};
|
||||
window.ADSLocalDropzone.instances[txtid] = instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
function isAccepted(file) {
|
||||
if (!acceptedFiles) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var name = String(file && file.name || '').toLowerCase();
|
||||
var type = String(file && file.type || '').toLowerCase();
|
||||
var accepted = acceptedFiles.split(',');
|
||||
|
||||
for (var i = 0; i < accepted.length; i++) {
|
||||
var rule = $.trim(accepted[i]).toLowerCase();
|
||||
if (!rule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rule.charAt(0) === '.' && name.slice(-rule.length) === rule) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rule.slice(-2) === '/*' &&
|
||||
type.indexOf(rule.substring(0, rule.length - 1)) === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type && type === rule) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function readFile(file, instance) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAccepted(file)) {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
'El tipo de archivo no está permitido.',
|
||||
instance
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > maxFilesize * 1024 * 1024) {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
'El archivo excede el tamaño permitido.',
|
||||
instance
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function (event) {
|
||||
txt.trigger('adsdropzone:fileadded', [
|
||||
file,
|
||||
event.target.result,
|
||||
instance
|
||||
]);
|
||||
};
|
||||
|
||||
reader.onerror = function () {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
'No fue posible leer el archivo seleccionado.',
|
||||
instance
|
||||
]);
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
/*
|
||||
* El proyecto recibido conserva el helper histórico ADDropzone(), pero no
|
||||
* contiene la librería Dropzone dentro de sus bundles. Para que el GIS no
|
||||
* dependa de una referencia externa, este componente tiene un fallback
|
||||
* nativo que mantiene la misma experiencia: clic, drag/drop, vista del
|
||||
* archivo y los mismos eventos adsdropzone:* consumidos por la pantalla.
|
||||
* Si Dropzone está cargado en otra instalación, se usa normalmente.
|
||||
*/
|
||||
if (typeof Dropzone === 'undefined') {
|
||||
var input = $('<input type="file" style="display:none;" />');
|
||||
if (acceptedFiles) {
|
||||
input.attr('accept', acceptedFiles);
|
||||
}
|
||||
if (isNaN(maxFile) || maxFile !== 1) {
|
||||
input.attr('multiple', 'multiple');
|
||||
}
|
||||
mydiv.append(input);
|
||||
|
||||
var fallback = {
|
||||
files: [],
|
||||
removeFile: function (file) {
|
||||
var index = this.files.indexOf(file);
|
||||
if (index >= 0) {
|
||||
this.files.splice(index, 1);
|
||||
}
|
||||
renderFallback();
|
||||
txt.trigger('adsdropzone:fileremoved', [file, fallback]);
|
||||
},
|
||||
removeAllFiles: function () {
|
||||
var files = this.files.slice(0);
|
||||
this.files = [];
|
||||
renderFallback();
|
||||
$.each(files, function (_, file) {
|
||||
txt.trigger('adsdropzone:fileremoved', [file, fallback]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function renderFallback() {
|
||||
mydiv.find('.ADSdropzoneLocalFallbackPreview').remove();
|
||||
mydiv.find('.dz-message').toggle(fallback.files.length === 0);
|
||||
|
||||
$.each(fallback.files, function (_, file) {
|
||||
var preview = $('<div class="ADSdropzoneLocalFallbackPreview"></div>');
|
||||
$('<div class="ADSdropzoneLocalFileName"></div>')
|
||||
.text(file.name)
|
||||
.appendTo(preview);
|
||||
$('<button type="button" class="btn btn-sm btn-block default">Quitar archivo</button>')
|
||||
.on('click', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
fallback.removeFile(file);
|
||||
})
|
||||
.appendTo(preview);
|
||||
mydiv.append(preview);
|
||||
});
|
||||
}
|
||||
|
||||
function addFallbackFile(file) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAccepted(file)) {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
'El tipo de archivo no está permitido.',
|
||||
fallback
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > maxFilesize * 1024 * 1024) {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
'El archivo excede el tamaño permitido.',
|
||||
fallback
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNaN(maxFile) && maxFile > 0 && fallback.files.length >= maxFile) {
|
||||
fallback.removeAllFiles();
|
||||
}
|
||||
|
||||
fallback.files.push(file);
|
||||
renderFallback();
|
||||
readFile(file, fallback);
|
||||
}
|
||||
|
||||
input.on('change', function () {
|
||||
var files = this.files || [];
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
addFallbackFile(files[i]);
|
||||
}
|
||||
this.value = '';
|
||||
});
|
||||
|
||||
mydiv.on('click', function (event) {
|
||||
if ($(event.target).is('button')) {
|
||||
return;
|
||||
}
|
||||
input.trigger('click');
|
||||
});
|
||||
|
||||
mydiv.on('keydown', function (event) {
|
||||
if (event.which === 13 || event.which === 32) {
|
||||
event.preventDefault();
|
||||
input.trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
mydiv.on('dragenter dragover', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
mydiv.addClass('is-dragging');
|
||||
});
|
||||
|
||||
mydiv.on('dragleave', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
mydiv.removeClass('is-dragging');
|
||||
});
|
||||
|
||||
mydiv.on('drop', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
mydiv.removeClass('is-dragging');
|
||||
|
||||
var original = event.originalEvent;
|
||||
var files = original && original.dataTransfer
|
||||
? original.dataTransfer.files
|
||||
: null;
|
||||
|
||||
if (!files) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
addFallbackFile(files[i]);
|
||||
}
|
||||
});
|
||||
|
||||
return registerInstance(fallback);
|
||||
}
|
||||
|
||||
var instance;
|
||||
|
||||
try {
|
||||
instance = new Dropzone('#' + dropId, {
|
||||
url: window.location.href,
|
||||
autoProcessQueue: false,
|
||||
uploadMultiple: false,
|
||||
parallelUploads: 1,
|
||||
maxFiles: isNaN(maxFile) || maxFile <= 0 ? null : maxFile,
|
||||
maxFilesize: maxFilesize,
|
||||
acceptedFiles: acceptedFiles,
|
||||
addRemoveLinks: true,
|
||||
dictDefaultMessage: message,
|
||||
dictRemoveFile: 'Quitar archivo',
|
||||
dictInvalidFileType: 'El tipo de archivo no está permitido.',
|
||||
dictFileTooBig: 'El archivo excede el tamaño permitido.',
|
||||
dictMaxFilesExceeded: 'Se excedió el número máximo de archivos.',
|
||||
init: function () {
|
||||
var dz = this;
|
||||
|
||||
dz.on('addedfile', function (file) {
|
||||
if (dz.options.maxFiles && dz.files.length > dz.options.maxFiles) {
|
||||
dz.removeFile(file);
|
||||
return;
|
||||
}
|
||||
|
||||
readFile(file, dz);
|
||||
});
|
||||
|
||||
dz.on('removedfile', function (file) {
|
||||
txt.trigger('adsdropzone:fileremoved', [file, dz]);
|
||||
});
|
||||
|
||||
dz.on('error', function (file, errorMessage) {
|
||||
txt.trigger('adsdropzone:fileerror', [
|
||||
file,
|
||||
typeof errorMessage === 'string'
|
||||
? errorMessage
|
||||
: 'El archivo seleccionado no es válido.',
|
||||
dz
|
||||
]);
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (ex) {
|
||||
mydiv.remove();
|
||||
txt.removeAttr('data-sig-dropzone-local-initialized');
|
||||
console.error('ADDropzoneLocal Error:', ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
return registerInstance(instance);
|
||||
}
|
||||
|
||||
window.ADSLocalDropzone = window.ADSLocalDropzone || {};
|
||||
window.ADSLocalDropzone.instances = window.ADSLocalDropzone.instances || {};
|
||||
window.ADSLocalDropzone.instance = function (txtid) {
|
||||
return window.ADSLocalDropzone.instances[txtid] || null;
|
||||
};
|
||||
window.ADSLocalDropzone.getFiles = function (txtid) {
|
||||
var instance = window.ADSLocalDropzone.instance(txtid);
|
||||
return instance && instance.files ? instance.files.slice(0) : [];
|
||||
};
|
||||
window.ADSLocalDropzone.getFile = function (txtid) {
|
||||
var files = window.ADSLocalDropzone.getFiles(txtid);
|
||||
return files.length ? files[files.length - 1] : null;
|
||||
};
|
||||
window.ADSLocalDropzone.clear = function (txtid) {
|
||||
var instance = window.ADSLocalDropzone.instance(txtid);
|
||||
if (instance && typeof instance.removeAllFiles === 'function') {
|
||||
instance.removeAllFiles(true);
|
||||
}
|
||||
};
|
||||
|
||||
function loadAdDropzoneLocal() {
|
||||
$('.ADSdropzoneLocal[id]').each(function () {
|
||||
ADDropzoneLocal($(this).attr('id'));
|
||||
});
|
||||
}
|
||||
function setwebservice(idDdlWS, idhdValue, idhdText, btn) {
|
||||
var DdlWS = $("#" + idDdlWS);
|
||||
var hdValue = $("#" + idhdValue);
|
||||
@@ -2640,6 +2990,7 @@ jQuery(document).ready(function () {
|
||||
DataTablePaginatorScroll();
|
||||
DataTablePaginatorScroll2();
|
||||
loadAdDropzone();
|
||||
loadAdDropzoneLocal();
|
||||
clonsbuttons();
|
||||
ADScroller2();
|
||||
//setTimeout(ADScroller2, 500);
|
||||
|
||||
1144
SIG.Web/Scripts/fraccionamiento-gis.js
Normal file
1144
SIG.Web/Scripts/fraccionamiento-gis.js
Normal file
File diff suppressed because it is too large
Load Diff
166
SIG.Web/Styles/fraccionamiento-gis.css
Normal file
166
SIG.Web/Styles/fraccionamiento-gis.css
Normal file
@@ -0,0 +1,166 @@
|
||||
#ModalStageGis .modal-dialog {
|
||||
width: 94%;
|
||||
max-width: 1280px;
|
||||
}
|
||||
|
||||
.sig-gis-layout {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.sig-gis-panel {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sig-gis-panel-files {
|
||||
flex: 0 0 34%;
|
||||
}
|
||||
|
||||
.sig-gis-panel-map {
|
||||
flex: 1 1 66%;
|
||||
}
|
||||
|
||||
.sig-gis-map {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 480px;
|
||||
border: 1px solid #d9dee4;
|
||||
background: #f7f9fb;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sig-gis-svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 480px;
|
||||
background: #f7f9fb;
|
||||
}
|
||||
|
||||
.sig-gis-polygon {
|
||||
cursor: pointer;
|
||||
stroke: #337ab7;
|
||||
stroke-width: 2;
|
||||
vector-effect: non-scaling-stroke;
|
||||
transition: opacity .15s ease, stroke-width .15s ease;
|
||||
}
|
||||
|
||||
.sig-gis-polygon.is-pending {
|
||||
fill: rgba(240, 173, 78, .28);
|
||||
}
|
||||
|
||||
.sig-gis-polygon.is-linked {
|
||||
fill: rgba(92, 184, 92, .34);
|
||||
stroke-width: 3;
|
||||
}
|
||||
|
||||
.sig-gis-polygon:hover {
|
||||
opacity: .8;
|
||||
stroke-width: 4;
|
||||
}
|
||||
|
||||
.sig-gis-map-note {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
bottom: 8px;
|
||||
padding: 4px 8px;
|
||||
background: rgba(255,255,255,.9);
|
||||
border: 1px solid #d9dee4;
|
||||
font-size: 11px;
|
||||
color: #6b7683;
|
||||
}
|
||||
|
||||
.sig-gis-links {
|
||||
max-height: 330px;
|
||||
overflow: auto;
|
||||
border: 1px solid #e6e9ed;
|
||||
}
|
||||
|
||||
.sig-gis-links-table {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.sig-gis-links-table td,
|
||||
.sig-gis-links-table th {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.sig-gis-link-status {
|
||||
margin: 10px 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sig-gis-empty {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.ADSdropzoneLocalContainer {
|
||||
min-height: 118px;
|
||||
padding: 18px;
|
||||
border: 2px dashed #c6ccd2;
|
||||
background: #fbfcfd;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ADSdropzoneLocalContainer .dz-message {
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
color: #687482;
|
||||
}
|
||||
|
||||
.ADSdropzoneLocalContainer .dz-preview {
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
.sig-gis-current-file {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.sig-gis-assign-modal {
|
||||
z-index: 1060;
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
#ModalStageGis .modal-dialog {
|
||||
width: auto;
|
||||
max-width: none;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.sig-gis-layout {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sig-gis-panel-files,
|
||||
.sig-gis-panel-map {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sig-gis-panel-map {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.sig-gis-map,
|
||||
.sig-gis-svg {
|
||||
min-height: 360px;
|
||||
height: 360px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.ADSdropzoneLocalContainer.is-dragging {
|
||||
border-style: solid;
|
||||
background: #eef6fb;
|
||||
}
|
||||
|
||||
.ADSdropzoneLocalFallbackPreview {
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
border: 1px solid #d9dee4;
|
||||
}
|
||||
|
||||
.ADSdropzoneLocalFileName {
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
word-break: break-all;
|
||||
}
|
||||
@@ -69,6 +69,13 @@
|
||||
|
||||
<system.webServer>
|
||||
<modules runAllManagedModulesForAllRequests="true" />
|
||||
<security>
|
||||
<requestFiltering>
|
||||
<hiddenSegments>
|
||||
<add segment="Documentos" />
|
||||
</hiddenSegments>
|
||||
</requestFiltering>
|
||||
</security>
|
||||
<handlers>
|
||||
<add name="PdfViewerHandler" path="SigPdfViewerHandler.ashx" verb="*" type="SIG.Web.AppCode.SigControls.PDFViewer.PdfViewerHandler" resourceType="Unspecified" />
|
||||
<add name="PdfViewerUploadHandler" path="SigPdfViewerUploadHandler.ashx" verb="POST" type="SIG.Web.AppCode.SigControls.PDFViewer.PdfViewerUploadHandler" resourceType="Unspecified" />
|
||||
|
||||
Binary file not shown.
81
tools/PA_Fraccionamientos_EtapaDocumentoGet.sql
Normal file
81
tools/PA_Fraccionamientos_EtapaDocumentoGet.sql
Normal file
@@ -0,0 +1,81 @@
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PA_Fraccionamientos_EtapaDocumentoGet]
|
||||
@CveFraccionamientoEtapa int,
|
||||
@CveUsuarioEjecuta int,
|
||||
@ErrorMostrar varchar(max) OUTPUT,
|
||||
@ErrorTipo int OUTPUT,
|
||||
@Return bit OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
@ErrorMostrar = NULL,
|
||||
@ErrorTipo = 0,
|
||||
@Return = 0;
|
||||
|
||||
BEGIN TRY
|
||||
DECLARE @NombreRol varchar(100);
|
||||
|
||||
SELECT @NombreRol = R.NombreRol
|
||||
FROM dbo.Sis_Usuarios AS U
|
||||
INNER JOIN dbo.Sis_Roles AS R
|
||||
ON R.CveRol = U.CveRol
|
||||
WHERE U.CveUsuario = @CveUsuarioEjecuta
|
||||
AND U.Activo = 1;
|
||||
|
||||
IF @NombreRol IS NULL
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'El usuario no está disponible para consultar documentos.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
SELECT
|
||||
E.CveFraccionamientoEtapa,
|
||||
E.CveFraccionamiento,
|
||||
F.CveCliente,
|
||||
E.Etapa
|
||||
FROM dbo.FraccionamientosEtapas AS E
|
||||
INNER JOIN dbo.Fraccionamientos AS F
|
||||
ON F.CveFraccionamiento = E.CveFraccionamiento
|
||||
WHERE E.CveFraccionamientoEtapa = @CveFraccionamientoEtapa
|
||||
AND
|
||||
(
|
||||
@NombreRol <> 'Empresa'
|
||||
OR EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM dbo.Sis_UsuariosClientes AS UC
|
||||
WHERE UC.CveUsuario = @CveUsuarioEjecuta
|
||||
AND UC.CveCliente = F.CveCliente
|
||||
AND UC.Activo = 1
|
||||
)
|
||||
);
|
||||
|
||||
IF @@ROWCOUNT = 0
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'La etapa no existe o no está asignada al usuario.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
SET @Return = 1;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
SET @ErrorMostrar = 'Ocurrió un error al validar el acceso al documento; favor de contactar a Sistemas.';
|
||||
SET @ErrorTipo = 1;
|
||||
SET @Return = 0;
|
||||
|
||||
DECLARE @ErrorTecnico nvarchar(2048) = CONCAT(
|
||||
'Número: ', ERROR_NUMBER(),
|
||||
'; Procedimiento: ', COALESCE(
|
||||
ERROR_PROCEDURE(),
|
||||
'PA_Fraccionamientos_EtapaDocumentoGet'),
|
||||
'; Línea: ', ERROR_LINE(),
|
||||
'; Detalle: ', ERROR_MESSAGE()
|
||||
);
|
||||
|
||||
RAISERROR(N'%s', 10, 1, @ErrorTecnico);
|
||||
END CATCH;
|
||||
END;
|
||||
GO
|
||||
95
tools/PA_Fraccionamientos_EtapaGISGet.sql
Normal file
95
tools/PA_Fraccionamientos_EtapaGISGet.sql
Normal file
@@ -0,0 +1,95 @@
|
||||
ALTER PROCEDURE [dbo].[PA_Fraccionamientos_EtapaGISGet]
|
||||
@CveFraccionamientoEtapa int,
|
||||
@CveUsuarioEjecuta int,
|
||||
@ErrorMostrar varchar(max) OUTPUT,
|
||||
@ErrorTipo int OUTPUT,
|
||||
@Return bit OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
@ErrorMostrar = NULL,
|
||||
@ErrorTipo = 0,
|
||||
@Return = 0;
|
||||
|
||||
BEGIN TRY
|
||||
DECLARE @NombreRol varchar(100);
|
||||
|
||||
SELECT @NombreRol = R.NombreRol
|
||||
FROM dbo.Sis_Usuarios AS U
|
||||
INNER JOIN dbo.Sis_Roles AS R
|
||||
ON R.CveRol = U.CveRol
|
||||
WHERE U.CveUsuario = @CveUsuarioEjecuta
|
||||
AND U.Activo = 1;
|
||||
|
||||
IF @NombreRol IS NULL
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'El usuario no está disponible para consultar el GIS.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
IF NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM dbo.FraccionamientosEtapas AS E
|
||||
INNER JOIN dbo.Fraccionamientos AS F
|
||||
ON F.CveFraccionamiento = E.CveFraccionamiento
|
||||
WHERE E.CveFraccionamientoEtapa = @CveFraccionamientoEtapa
|
||||
AND
|
||||
(
|
||||
@NombreRol <> 'Empresa'
|
||||
OR EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM dbo.Sis_UsuariosClientes AS UC
|
||||
WHERE UC.CveUsuario = @CveUsuarioEjecuta
|
||||
AND UC.CveCliente = F.CveCliente
|
||||
AND UC.Activo = 1
|
||||
)
|
||||
)
|
||||
)
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'La etapa no existe o no está asignada al usuario.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
SELECT
|
||||
G.CveFraccionamientoEtapaGIS,
|
||||
G.CveFraccionamientoEtapa,
|
||||
E.CveFraccionamiento,
|
||||
F.CveCliente,
|
||||
E.Etapa,
|
||||
G.Nombre,
|
||||
G.UrlVisualizacion,
|
||||
G.FechaAlta,
|
||||
G.FechaModificacion
|
||||
FROM dbo.FraccionamientosEtapasGIS AS G
|
||||
INNER JOIN dbo.FraccionamientosEtapas AS E
|
||||
ON E.CveFraccionamientoEtapa = G.CveFraccionamientoEtapa
|
||||
INNER JOIN dbo.Fraccionamientos AS F
|
||||
ON F.CveFraccionamiento = E.CveFraccionamiento
|
||||
WHERE G.CveFraccionamientoEtapa = @CveFraccionamientoEtapa;
|
||||
|
||||
SET @Return = 1;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
SET @ErrorMostrar = 'Ocurrió un error al consultar el GIS de la etapa; favor de contactar a Sistemas.';
|
||||
SET @ErrorTipo = 1;
|
||||
SET @Return = 0;
|
||||
|
||||
DECLARE @ErrorTecnico nvarchar(2048) = CONCAT(
|
||||
'Número: ', ERROR_NUMBER(),
|
||||
'; Procedimiento: ', COALESCE(
|
||||
ERROR_PROCEDURE(),
|
||||
'PA_Fraccionamientos_EtapaGISGet'),
|
||||
'; Línea: ', ERROR_LINE(),
|
||||
'; Detalle: ', ERROR_MESSAGE()
|
||||
);
|
||||
|
||||
RAISERROR(N'%s', 10, 1, @ErrorTecnico);
|
||||
END CATCH;
|
||||
END;
|
||||
GO
|
||||
168
tools/PA_Fraccionamientos_EtapaGISSave.sql
Normal file
168
tools/PA_Fraccionamientos_EtapaGISSave.sql
Normal file
@@ -0,0 +1,168 @@
|
||||
ALTER PROCEDURE [dbo].[PA_Fraccionamientos_EtapaGISSave]
|
||||
@CveFraccionamientoEtapa int,
|
||||
@Nombre varchar(200) = NULL,
|
||||
@UrlVisualizacion varchar(2000) = NULL,
|
||||
@CveUsuarioEjecuta int,
|
||||
@ErrorMostrar varchar(max) OUTPUT,
|
||||
@ErrorTipo int OUTPUT,
|
||||
@Return bit OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
@ErrorMostrar = NULL,
|
||||
@ErrorTipo = 0,
|
||||
@Return = 0;
|
||||
|
||||
BEGIN TRY
|
||||
DECLARE @NombreRol varchar(100);
|
||||
DECLARE @CveFraccionamiento int;
|
||||
DECLARE @CveCliente int;
|
||||
DECLARE @Etapa varchar(150);
|
||||
|
||||
SELECT @NombreRol = R.NombreRol
|
||||
FROM dbo.Sis_Usuarios AS U
|
||||
INNER JOIN dbo.Sis_Roles AS R
|
||||
ON R.CveRol = U.CveRol
|
||||
WHERE U.CveUsuario = @CveUsuarioEjecuta
|
||||
AND U.Activo = 1;
|
||||
|
||||
IF @NombreRol IS NULL
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'El usuario no está disponible para guardar el GIS.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
SELECT
|
||||
@CveFraccionamiento = E.CveFraccionamiento,
|
||||
@CveCliente = F.CveCliente,
|
||||
@Etapa = E.Etapa
|
||||
FROM dbo.FraccionamientosEtapas AS E
|
||||
INNER JOIN dbo.Fraccionamientos AS F
|
||||
ON F.CveFraccionamiento = E.CveFraccionamiento
|
||||
WHERE E.CveFraccionamientoEtapa = @CveFraccionamientoEtapa
|
||||
AND
|
||||
(
|
||||
@NombreRol <> 'Empresa'
|
||||
OR EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM dbo.Sis_UsuariosClientes AS UC
|
||||
WHERE UC.CveUsuario = @CveUsuarioEjecuta
|
||||
AND UC.CveCliente = F.CveCliente
|
||||
AND UC.Activo = 1
|
||||
)
|
||||
);
|
||||
|
||||
IF @CveFraccionamiento IS NULL
|
||||
BEGIN
|
||||
SET @ErrorMostrar = 'La etapa no existe o no está asignada al usuario.';
|
||||
SET @ErrorTipo = 2;
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
SET @Nombre = CONCAT(
|
||||
'gis-',
|
||||
@CveFraccionamiento,
|
||||
'-',
|
||||
@CveFraccionamientoEtapa,
|
||||
'.gis');
|
||||
|
||||
SET @UrlVisualizacion = CONCAT(
|
||||
'~/Pages/Fraccionamientos/FraccionamientoGis.ashx?etapa=',
|
||||
@CveFraccionamientoEtapa);
|
||||
|
||||
DECLARE @CveFraccionamientoEtapaGIS int;
|
||||
DECLARE @NombreAnterior varchar(200);
|
||||
DECLARE @UrlVisualizacionAnterior varchar(2000);
|
||||
DECLARE @EsNuevo bit = 0;
|
||||
DECLARE @HuboCambio bit = 0;
|
||||
|
||||
SELECT
|
||||
@CveFraccionamientoEtapaGIS = G.CveFraccionamientoEtapaGIS,
|
||||
@NombreAnterior = G.Nombre,
|
||||
@UrlVisualizacionAnterior = G.UrlVisualizacion
|
||||
FROM dbo.FraccionamientosEtapasGIS AS G WITH (UPDLOCK, HOLDLOCK)
|
||||
WHERE G.CveFraccionamientoEtapa = @CveFraccionamientoEtapa;
|
||||
|
||||
IF @CveFraccionamientoEtapaGIS IS NULL
|
||||
BEGIN
|
||||
INSERT INTO dbo.FraccionamientosEtapasGIS
|
||||
(
|
||||
CveFraccionamientoEtapa,
|
||||
Nombre,
|
||||
UrlVisualizacion,
|
||||
CveUsuario
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@CveFraccionamientoEtapa,
|
||||
@Nombre,
|
||||
@UrlVisualizacion,
|
||||
@CveUsuarioEjecuta
|
||||
);
|
||||
|
||||
SET @CveFraccionamientoEtapaGIS = CONVERT(
|
||||
int,
|
||||
SCOPE_IDENTITY());
|
||||
SET @EsNuevo = 1;
|
||||
SET @HuboCambio = 1;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
UPDATE dbo.FraccionamientosEtapasGIS
|
||||
SET
|
||||
Nombre = @Nombre,
|
||||
UrlVisualizacion = @UrlVisualizacion,
|
||||
FechaModificacion = GETDATE(),
|
||||
CveUsuario = @CveUsuarioEjecuta
|
||||
WHERE CveFraccionamientoEtapaGIS =
|
||||
@CveFraccionamientoEtapaGIS;
|
||||
|
||||
SET @HuboCambio = 1;
|
||||
END;
|
||||
|
||||
SELECT
|
||||
G.CveFraccionamientoEtapaGIS,
|
||||
G.CveFraccionamientoEtapa,
|
||||
E.CveFraccionamiento,
|
||||
F.CveCliente,
|
||||
E.Etapa,
|
||||
G.Nombre,
|
||||
G.UrlVisualizacion,
|
||||
@NombreAnterior AS NombreAnterior,
|
||||
@UrlVisualizacionAnterior AS UrlVisualizacionAnterior,
|
||||
@EsNuevo AS EsNuevo,
|
||||
@HuboCambio AS HuboCambio,
|
||||
G.FechaAlta,
|
||||
G.FechaModificacion
|
||||
FROM dbo.FraccionamientosEtapasGIS AS G
|
||||
INNER JOIN dbo.FraccionamientosEtapas AS E
|
||||
ON E.CveFraccionamientoEtapa = G.CveFraccionamientoEtapa
|
||||
INNER JOIN dbo.Fraccionamientos AS F
|
||||
ON F.CveFraccionamiento = E.CveFraccionamiento
|
||||
WHERE G.CveFraccionamientoEtapaGIS =
|
||||
@CveFraccionamientoEtapaGIS;
|
||||
|
||||
SET @Return = 1;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
SET @ErrorMostrar = 'Ocurrió un error al guardar el GIS de la etapa; favor de contactar a Sistemas.';
|
||||
SET @ErrorTipo = 1;
|
||||
SET @Return = 0;
|
||||
|
||||
DECLARE @ErrorTecnico nvarchar(2048) = CONCAT(
|
||||
'Número: ', ERROR_NUMBER(),
|
||||
'; Procedimiento: ', COALESCE(
|
||||
ERROR_PROCEDURE(),
|
||||
'PA_Fraccionamientos_EtapaGISSave'),
|
||||
'; Línea: ', ERROR_LINE(),
|
||||
'; Detalle: ', ERROR_MESSAGE()
|
||||
);
|
||||
|
||||
RAISERROR(N'%s', 10, 1, @ErrorTecnico);
|
||||
END CATCH;
|
||||
END;
|
||||
GO
|
||||
Reference in New Issue
Block a user