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; } = string.Empty; [Required] [StringLength(150)] [Column("apellidos")] public string Apellidos { get; set; } = string.Empty; [Required] [Column("fecha_nacimiento")] public DateTime FechaNacimiento { get; set; } [Required] [StringLength(1)] [Column("sexo")] 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; } [StringLength(20)] [Column("telefono")] public string? Telefono { get; set; } [Column("observaciones")] public string? Observaciones { get; set; } [StringLength(500)] [Column("foto_url")] 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 // ============================ [NotMapped] public string NombreCompleto => $"{Nombre} {Apellidos}".Trim(); [NotMapped] public int Edad { get { var today = DateTime.Today; var age = today.Year - FechaNacimiento.Year; if (FechaNacimiento.Date > today.AddYears(-age)) age--; return age; } } [NotMapped] public string EdadConMeses { get { var today = DateTime.Today; var age = today.Year - FechaNacimiento.Year; var months = today.Month - FechaNacimiento.Month; if (today.Day < FechaNacimiento.Day) months--; if (months < 0) { age--; months += 12; } return $"{age} años, {months} meses"; } } [NotMapped] public string NombreConEdad => $"{NombreCompleto} ({Edad} años)"; [NotMapped] public string InformacionBasica => $"{NombreCompleto} | {Edad} años | {Sexo}"; } }