Todo
This commit is contained in:
@@ -51,5 +51,57 @@ namespace MieSystem.Models
|
||||
|
||||
[Column("activo")]
|
||||
public bool Activo { get; set; }
|
||||
|
||||
|
||||
|
||||
// Propiedades calculadas (solo lectura)
|
||||
public string NombreCompleto => $"{Nombre} {Apellidos}".Trim();
|
||||
|
||||
public int Edad
|
||||
{
|
||||
get
|
||||
{
|
||||
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
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
// Para mostrar en selectores
|
||||
public string NombreConEdad => $"{NombreCompleto} ({Edad} años)";
|
||||
|
||||
// Para mostrar en listas
|
||||
public string InformacionBasica => $"{NombreCompleto} | {Edad} años | {Sexo}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user