Todo
This commit is contained in:
@@ -2,12 +2,9 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MieSystem.Models;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using MieSystem.Models;
|
||||
using MieSystem.Data.Interfaces;
|
||||
using AspNetCoreGeneratedDocument;
|
||||
using MieSystem.Models.ViewModels;
|
||||
|
||||
namespace MieSystem.Controllers
|
||||
{
|
||||
@@ -25,104 +22,22 @@ namespace MieSystem.Controllers
|
||||
_expedienteRepository = expedienteRepository;
|
||||
|
||||
// Datos de prueba iniciales
|
||||
if (_expedientes.Count == 0)
|
||||
/*if (_expedientes.Count == 0)
|
||||
{
|
||||
|
||||
_ = InitializeTestData();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private async Task InitializeTestData()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var lst = await _expedienteRepository.GetAllAsync();
|
||||
_expedientes =new List<Expediente>(lst);
|
||||
|
||||
/*_expedientes.Add(new Expediente
|
||||
{
|
||||
Id = _idCounter++,
|
||||
Nombre = "Juan",
|
||||
Apellidos = "Pérez García",
|
||||
FechaNacimiento = new DateTime(2015, 5, 10),
|
||||
NombrePadre = "Carlos Pérez",
|
||||
NombreMadre = "María García",
|
||||
NombreResponsable = "Carlos Pérez",
|
||||
ParentescoResponsable = "Padre",
|
||||
Sexo = "M",
|
||||
Direccion = "Calle Principal 123, Ciudad",
|
||||
Telefono = "555-1234",
|
||||
Observaciones = "Niño tranquilo",
|
||||
FotoUrl = "/images/default-avatar.png",
|
||||
FechaCreacion = DateTime.Now.AddDays(-30),
|
||||
FechaActualizacion = DateTime.Now.AddDays(-30),
|
||||
Activo = true
|
||||
});
|
||||
|
||||
_expedientes.Add(new Expediente
|
||||
{
|
||||
Id = _idCounter++,
|
||||
Nombre = "Ana",
|
||||
Apellidos = "López Martínez",
|
||||
FechaNacimiento = new DateTime(2016, today.Month, 15), // Cumple este mes
|
||||
NombrePadre = "Pedro López",
|
||||
NombreMadre = "Laura Martínez",
|
||||
NombreResponsable = "Laura Martínez",
|
||||
ParentescoResponsable = "Madre",
|
||||
Sexo = "F",
|
||||
Direccion = "Avenida Central 456, Ciudad",
|
||||
Telefono = "555-5678",
|
||||
Observaciones = "Alergia a los frutos secos",
|
||||
FotoUrl = "/images/default-avatar.png",
|
||||
FechaCreacion = DateTime.Now.AddDays(-15),
|
||||
FechaActualizacion = DateTime.Now.AddDays(-15),
|
||||
Activo = true
|
||||
});
|
||||
|
||||
_expedientes.Add(new Expediente
|
||||
{
|
||||
Id = _idCounter++,
|
||||
Nombre = "Carlos",
|
||||
Apellidos = "Rodríguez Sánchez",
|
||||
FechaNacimiento = new DateTime(2008, 8, 20), // Mayor de 14 años
|
||||
NombrePadre = "Javier Rodríguez",
|
||||
NombreMadre = "Carmen Sánchez",
|
||||
NombreResponsable = "Javier Rodríguez",
|
||||
ParentescoResponsable = "Padre",
|
||||
Sexo = "M",
|
||||
Direccion = "Plaza Mayor 789, Ciudad",
|
||||
Telefono = "555-9012",
|
||||
Observaciones = "Excelente estudiante",
|
||||
FotoUrl = "/images/default-avatar.png",
|
||||
FechaCreacion = DateTime.Now.AddDays(-60),
|
||||
FechaActualizacion = DateTime.Now.AddDays(-60),
|
||||
Activo = true
|
||||
});
|
||||
|
||||
_expedientes.Add(new Expediente
|
||||
{
|
||||
Id = _idCounter++,
|
||||
Nombre = "María",
|
||||
Apellidos = "Gómez Fernández",
|
||||
FechaNacimiento = new DateTime(2017, 11, 5),
|
||||
NombrePadre = "Luis Gómez",
|
||||
NombreMadre = "Sofía Fernández",
|
||||
NombreResponsable = "Sofía Fernández",
|
||||
ParentescoResponsable = "Madre",
|
||||
Sexo = "F",
|
||||
Direccion = "Calle Secundaria 101, Ciudad",
|
||||
Telefono = "555-3456",
|
||||
Observaciones = "Necesita atención especial en matemáticas",
|
||||
FotoUrl = "/images/default-avatar.png",
|
||||
FechaCreacion = DateTime.Now.AddDays(-45),
|
||||
FechaActualizacion = DateTime.Now.AddDays(-45),
|
||||
Activo = true
|
||||
});*/
|
||||
_expedientes = [.. lst];
|
||||
}
|
||||
|
||||
// GET: Expedientes
|
||||
public IActionResult Index()
|
||||
{
|
||||
_ = InitializeTestData();
|
||||
return View();
|
||||
}
|
||||
|
||||
@@ -130,6 +45,7 @@ namespace MieSystem.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult GetDashboardStats()
|
||||
{
|
||||
_ = InitializeTestData();
|
||||
var totalNinos = _expedientes.Count;
|
||||
var mesActual = DateTime.Now.Month;
|
||||
|
||||
@@ -162,6 +78,9 @@ namespace MieSystem.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult GetExpedientes(int page = 1, int pageSize = 10)
|
||||
{
|
||||
if (_expedientes.Count == 0)
|
||||
_ = InitializeTestData();
|
||||
|
||||
var query = _expedientes
|
||||
.Where(e => e.Activo)
|
||||
.OrderBy(e => e.Apellidos)
|
||||
@@ -316,7 +235,8 @@ namespace MieSystem.Controllers
|
||||
ModelState.Remove("Observaciones");
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var expediente = _expedientes.FirstOrDefault(e => e.Id == id);
|
||||
var expediente = await _expedienteRepository.GetByIdAsync(id);
|
||||
//var expediente = _expedientes.FirstOrDefault(e => e.Id == id);
|
||||
if (expediente == null)
|
||||
{
|
||||
return Json(new { success = false, message = "Expediente no encontrado" });
|
||||
@@ -359,6 +279,7 @@ namespace MieSystem.Controllers
|
||||
}
|
||||
|
||||
// Actualizar datos
|
||||
expediente.Id = id;
|
||||
expediente.Nombre = model.Nombre;
|
||||
expediente.Apellidos = model.Apellidos;
|
||||
expediente.FechaNacimiento = model.FechaNacimiento;
|
||||
@@ -373,7 +294,16 @@ namespace MieSystem.Controllers
|
||||
expediente.FotoUrl = fotoUrlActual;
|
||||
expediente.FechaActualizacion = DateTime.Now;
|
||||
|
||||
return Json(new { success = true, message = "Expediente actualizado exitosamente" });
|
||||
try
|
||||
{
|
||||
await _expedienteRepository.UpdateAsync(expediente);
|
||||
return Json(new { success = true, message = "Expediente actualizado exitosamente" });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { success = false, message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = false, message = "Error en los datos del formulario" });
|
||||
|
||||
Reference in New Issue
Block a user