Nueva mejoras Y estabilidad
This commit is contained in:
@@ -1,41 +1,30 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MieSystem.Data.Interfaces;
|
||||
using MieSystem.Models;
|
||||
using MieSystem.Models.ViewModels;
|
||||
using MieSystem.Services;
|
||||
|
||||
namespace MieSystem.Controllers
|
||||
{
|
||||
public class AsistenciaController : Controller
|
||||
{
|
||||
private readonly IExpedienteRepository _expedienteRepository;
|
||||
private readonly IAsistenciaRepository _asistenciaRepository;
|
||||
|
||||
public AsistenciaController(
|
||||
IExpedienteRepository expedienteRepository,
|
||||
IAsistenciaRepository asistenciaRepository)
|
||||
private readonly ExpedienteService expedienteService;
|
||||
private readonly AsistenciaService asistenciaService;
|
||||
public AsistenciaController(ExpedienteService expedienteService, AsistenciaService asistenciaService)
|
||||
{
|
||||
_expedienteRepository = expedienteRepository;
|
||||
_asistenciaRepository = asistenciaRepository;
|
||||
this.expedienteService = expedienteService;
|
||||
this.asistenciaService = asistenciaService;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index(int? año, int? mes, string diasSemana = null)
|
||||
{
|
||||
// Valores por defecto: mes actual
|
||||
var fechaActual = DateTime.Now;
|
||||
var añoSeleccionado = año ?? fechaActual.Year;
|
||||
var mesSeleccionado = mes ?? fechaActual.Month;
|
||||
|
||||
// Obtener todos los niños activos
|
||||
var expedientes = await _expedienteRepository.GetActivosAsync();
|
||||
var expedientes = await expedienteService.GetActivosAsync();
|
||||
|
||||
// Obtener días del mes seleccionado
|
||||
var diasDelMes = GetDiasDelMes(añoSeleccionado, mesSeleccionado);
|
||||
|
||||
// Filtrar por días de semana si se especifica
|
||||
if (!string.IsNullOrEmpty(diasSemana))
|
||||
{
|
||||
var diasFiltro = diasSemana.Split(',')
|
||||
@@ -45,7 +34,7 @@ namespace MieSystem.Controllers
|
||||
}
|
||||
|
||||
// Obtener asistencias para el mes
|
||||
var asistencias = await _asistenciaRepository.GetAsistenciasPorMesAsync(
|
||||
var asistencias = await asistenciaService.GetAsistenciasPorMesAsync(
|
||||
añoSeleccionado, mesSeleccionado);
|
||||
|
||||
// Crear diccionario para acceso rápido
|
||||
@@ -53,7 +42,7 @@ namespace MieSystem.Controllers
|
||||
foreach (var asistencia in asistencias)
|
||||
{
|
||||
var key = $"{asistencia.ExpedienteId}_{asistencia.Fecha:yyyy-MM-dd}";
|
||||
dictAsistencias[key] = asistencia.Estado;
|
||||
dictAsistencias[key] = asistencia.Estado.ToString();
|
||||
}
|
||||
|
||||
// Crear modelo de vista
|
||||
@@ -89,11 +78,11 @@ namespace MieSystem.Controllers
|
||||
{
|
||||
ExpedienteId = expedienteId,
|
||||
Fecha = fechaDate,
|
||||
Estado = estado,
|
||||
Estado = estado[0],
|
||||
UsuarioRegistro = User.Identity?.Name ?? "Sistema"
|
||||
};
|
||||
|
||||
var resultado = await _asistenciaRepository.GuardarAsistenciaAsync(asistencia);
|
||||
var resultado = await asistenciaService.SaveAsync(asistencia);
|
||||
|
||||
return Json(new { success = resultado, message = "Asistencia guardada" });
|
||||
}
|
||||
@@ -116,13 +105,13 @@ namespace MieSystem.Controllers
|
||||
{
|
||||
ExpedienteId = asistenciaDto.ExpedienteId,
|
||||
Fecha = asistenciaDto.Fecha,
|
||||
Estado = asistenciaDto.Estado,
|
||||
Estado = asistenciaDto.Estado[0],
|
||||
UsuarioRegistro = User.Identity?.Name ?? "Sistema"
|
||||
};
|
||||
asistenciasModel.Add(asistencia);
|
||||
}
|
||||
|
||||
var resultado = await _asistenciaRepository.GuardarAsistenciasMasivasAsync(asistenciasModel);
|
||||
var resultado = asistenciaService.GuardarAsistenciasMasivasAsync(asistenciasModel);
|
||||
|
||||
return Json(new
|
||||
{
|
||||
@@ -141,7 +130,7 @@ namespace MieSystem.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var estadisticas = await _asistenciaRepository.GetEstadisticasMesAsync(año, mes);
|
||||
var estadisticas = await asistenciaService.GetEstadisticasMesAsync(año, mes);
|
||||
return Json(estadisticas);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MieSystem.Data.Interfaces;
|
||||
using MieSystem.Models;
|
||||
using MieSystem.Models.ViewModels;
|
||||
using MieSystem.Services;
|
||||
|
||||
namespace MieSystem.Controllers
|
||||
{
|
||||
public class ExpedientesController : Controller
|
||||
{
|
||||
private static List<Expediente> _expedientes = new List<Expediente>();
|
||||
private static int _idCounter = 1;
|
||||
//private static int _idCounter = 1;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
|
||||
private readonly IExpedienteRepository _expedienteRepository;
|
||||
public ExpedientesController(IExpedienteRepository expedienteRepository, IWebHostEnvironment hostingEnvironment)
|
||||
private readonly ExpedienteService expedienteService;
|
||||
|
||||
public ExpedientesController(ExpedienteService expedienteService, IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
|
||||
_expedienteRepository = expedienteRepository;
|
||||
this.expedienteService = expedienteService;
|
||||
}
|
||||
|
||||
// GET: Expedientes
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var lst = await _expedienteRepository.GetAllAsync();
|
||||
var lst = await expedienteService.GetAllAsync();
|
||||
_expedientes = [.. lst];
|
||||
return View();
|
||||
}
|
||||
@@ -83,7 +81,7 @@ namespace MieSystem.Controllers
|
||||
FechaNacimiento = e.FechaNacimiento,
|
||||
Sexo = e.Sexo,
|
||||
NombreResponsable = e.NombreResponsable,
|
||||
FotoUrl = e.FotoUrl
|
||||
FotoUrl = ExisteFoto(e.FotoUrl)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
@@ -140,7 +138,6 @@ namespace MieSystem.Controllers
|
||||
// Crear nuevo expediente
|
||||
var expediente = new Expediente
|
||||
{
|
||||
Id = _idCounter++,
|
||||
Nombre = model.Nombre,
|
||||
Apellidos = model.Apellidos,
|
||||
FechaNacimiento = model.FechaNacimiento,
|
||||
@@ -160,7 +157,8 @@ namespace MieSystem.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
await _expedienteRepository.CreateAsync(expediente);
|
||||
//await _expedienteRepository.CreateAsync(expediente);
|
||||
await expedienteService.SaveAsync(expediente);
|
||||
return Json(new { success = true, message = "Expediente creado exitosamente" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -217,7 +215,8 @@ namespace MieSystem.Controllers
|
||||
ModelState.Remove("Observaciones");
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var expediente = await _expedienteRepository.GetByIdAsync(id);
|
||||
//var expediente = await _expedienteRepository.GetByIdAsync(id);
|
||||
var expediente = await expedienteService.GetByIdAsync(id);
|
||||
//var expediente = _expedientes.FirstOrDefault(e => e.Id == id);
|
||||
if (expediente == null)
|
||||
{
|
||||
@@ -278,7 +277,8 @@ namespace MieSystem.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
await _expedienteRepository.UpdateAsync(expediente);
|
||||
//await _expedienteRepository.UpdateAsync(expediente);
|
||||
await expedienteService.SaveAsync(expediente);
|
||||
return Json(new { success = true, message = "Expediente actualizado exitosamente" });
|
||||
|
||||
}
|
||||
@@ -292,7 +292,7 @@ namespace MieSystem.Controllers
|
||||
}
|
||||
|
||||
// DELETE: Expedientes/Delete/5
|
||||
[HttpDelete]
|
||||
/*[HttpDelete]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var expediente = _expedientes.FirstOrDefault(e => e.Id == id);
|
||||
@@ -318,7 +318,7 @@ namespace MieSystem.Controllers
|
||||
|
||||
return Json(new { success = true, message = "Expediente eliminado exitosamente" });
|
||||
}
|
||||
|
||||
*/
|
||||
// GET: Expedientes/Details/5 (Opcional)
|
||||
public IActionResult Details(int id)
|
||||
{
|
||||
@@ -410,6 +410,23 @@ namespace MieSystem.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
public string ExisteFoto(string url)
|
||||
{
|
||||
if(string.IsNullOrEmpty(url))
|
||||
return Path.Combine("images", "default-avatar.png");
|
||||
|
||||
var uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", "fotos");
|
||||
string[] parts = url.Split('/');
|
||||
string name = parts[^1];
|
||||
|
||||
string fullpath = Path.Combine(uploadsFolder, name);
|
||||
|
||||
if (System.IO.File.Exists(fullpath))
|
||||
return url;
|
||||
|
||||
return Path.Combine("images", "default-avatar.png");
|
||||
}
|
||||
|
||||
// GET: Expedientes/DeleteImage
|
||||
[HttpDelete]
|
||||
public IActionResult DeleteImage(string imageUrl)
|
||||
|
||||
Reference in New Issue
Block a user