Nueva mejoras Y estabilidad
This commit is contained in:
@@ -1,62 +1,85 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace MieSystem.Models
|
||||
{
|
||||
[Table("expedientes")]
|
||||
public class Expediente
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
[StringLength(100)]
|
||||
[Column("nombre")]
|
||||
public string Nombre { get; set; }
|
||||
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(150)]
|
||||
[Column("apellidos")]
|
||||
public string Apellidos { get; set; }
|
||||
|
||||
public string Apellidos { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[Column("fecha_nacimiento")]
|
||||
public DateTime FechaNacimiento { get; set; }
|
||||
|
||||
[Column("nombre_padre")]
|
||||
public string NombrePadre { get; set; }
|
||||
|
||||
[Column("nombre_madre")]
|
||||
public string NombreMadre { get; set; }
|
||||
|
||||
[Column("nombre_responsable")]
|
||||
public string NombreResponsable { get; set; }
|
||||
|
||||
[Column("parentesco_responsable")]
|
||||
public string ParentescoResponsable { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
[StringLength(1)]
|
||||
[Column("sexo")]
|
||||
public string Sexo { get; set; }
|
||||
|
||||
public string Sexo { get; set; } = string.Empty;
|
||||
|
||||
[StringLength(150)]
|
||||
[Column("nombre_padre")]
|
||||
public string? NombrePadre { get; set; }
|
||||
|
||||
[StringLength(150)]
|
||||
[Column("nombre_madre")]
|
||||
public string? NombreMadre { get; set; }
|
||||
|
||||
[StringLength(150)]
|
||||
[Column("nombre_responsable")]
|
||||
public string? NombreResponsable { get; set; }
|
||||
|
||||
[StringLength(50)]
|
||||
[Column("parentesco_responsable")]
|
||||
public string? ParentescoResponsable { get; set; }
|
||||
|
||||
[Column("direccion")]
|
||||
public string Direccion { get; set; }
|
||||
|
||||
public string? Direccion { get; set; }
|
||||
|
||||
[StringLength(20)]
|
||||
[Column("telefono")]
|
||||
public string Telefono { get; set; }
|
||||
|
||||
public string? Telefono { get; set; }
|
||||
|
||||
[Column("observaciones")]
|
||||
public string Observaciones { get; set; }
|
||||
|
||||
public string? Observaciones { get; set; }
|
||||
|
||||
[StringLength(500)]
|
||||
[Column("foto_url")]
|
||||
public string FotoUrl { get; set; }
|
||||
|
||||
public string? FotoUrl { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("fecha_creacion")]
|
||||
public DateTime FechaCreacion { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
[Column("fecha_actualizacion")]
|
||||
public DateTime FechaActualizacion { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
[Column("activo")]
|
||||
public bool Activo { get; set; }
|
||||
|
||||
// ============================
|
||||
// 🔹 Propiedades calculadas
|
||||
// ============================
|
||||
|
||||
|
||||
// Propiedades calculadas (solo lectura)
|
||||
[NotMapped]
|
||||
public string NombreCompleto => $"{Nombre} {Apellidos}".Trim();
|
||||
|
||||
[NotMapped]
|
||||
public int Edad
|
||||
{
|
||||
get
|
||||
@@ -64,17 +87,14 @@ namespace MieSystem.Models
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - FechaNacimiento.Year;
|
||||
|
||||
// Si aún no ha cumplido años este año, restar 1
|
||||
if (FechaNacimiento.Date > today.AddYears(-age))
|
||||
{
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
// Otra propiedad útil para mostrar
|
||||
[NotMapped]
|
||||
public string EdadConMeses
|
||||
{
|
||||
get
|
||||
@@ -84,9 +104,7 @@ namespace MieSystem.Models
|
||||
var months = today.Month - FechaNacimiento.Month;
|
||||
|
||||
if (today.Day < FechaNacimiento.Day)
|
||||
{
|
||||
months--;
|
||||
}
|
||||
|
||||
if (months < 0)
|
||||
{
|
||||
@@ -98,10 +116,10 @@ namespace MieSystem.Models
|
||||
}
|
||||
}
|
||||
|
||||
// Para mostrar en selectores
|
||||
[NotMapped]
|
||||
public string NombreConEdad => $"{NombreCompleto} ({Edad} años)";
|
||||
|
||||
// Para mostrar en listas
|
||||
[NotMapped]
|
||||
public string InformacionBasica => $"{NombreCompleto} | {Edad} años | {Sexo}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user