Hermes/Model/Citoyen.cs

314 lines
8.8 KiB
C#

using System;
using Hermes.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Hermes.Model {
public class Citoyen : INotifyPropertyChanged {
private int _id;
private string _civilite;
private string _nom;
private string _nomNaissance;
private string _prenom;
private DateTime? _dateNaissance = null;
private string _profession;
private bool _typeResidence = false;
private string _mail;
private string _tel;
private string _telPort;
private string _quartier;
private string _adresse;
private string _adresseBatiment;
private string _adresseNumeroBatiment;
private string _adresseExt;
private string _adresseExtCP;
private string _adresseExtVille;
private DateTime _dateCreation;
private DateTime _dateModification;
public int Id {
get => _id; set => _id = value;
}
public string Civilite {
get => _civilite;
set {
_civilite = value;
OnPropertyChanged();
}
}
public string Nom {
get => _nom;
set {
_nom = value;
OnPropertyChanged();
}
}
public string NomNaissance {
get => _nomNaissance;
set {
_nomNaissance = value;
OnPropertyChanged();
}
}
public string Prenom {
get => _prenom;
set {
_prenom = value;
OnPropertyChanged();
}
}
public DateTime? DateNaissance {
get => _dateNaissance;
set {
_dateNaissance = value;
OnPropertyChanged();
OnPropertyChanged("Age");
}
}
public string Profession {
get => _profession;
set {
_profession = value;
OnPropertyChanged();
}
}
public bool TypeResidence {
get => _typeResidence;
set {
_typeResidence = value;
if(_typeResidence == false) {
AdresseExt = null;
AdresseExtCP = null;
AdresseExtVille = null;
}
OnPropertyChanged();
OnPropertyChanged("TypeResidenceLabel");
}
}
public string Mail {
get => _mail;
set {
_mail = value;
OnPropertyChanged();
}
}
public string Tel {
get => _tel;
set {
_tel = value;
OnPropertyChanged();
}
}
public string TelPort {
get => _telPort;
set {
_telPort = value;
OnPropertyChanged();
}
}
public string Quartier {
get => _quartier;
set {
_quartier = value;
OnPropertyChanged();
}
}
public string Adresse {
get => _adresse;
set {
_adresse = value;
OnPropertyChanged();
}
}
public string AdresseBatiment {
get => _adresseBatiment;
set {
_adresseBatiment = value;
OnPropertyChanged();
}
}
public string AdresseNumeroBatiment {
get => _adresseNumeroBatiment;
set {
_adresseNumeroBatiment = value;
OnPropertyChanged();
}
}
public string AdresseExt {
get => TypeResidence == false ? null : _adresseExt;
set {
_adresseExt = value;
OnPropertyChanged();
}
}
public string AdresseExtCP {
get => TypeResidence == false ? null : _adresseExtCP;
set {
_adresseExtCP = value;
OnPropertyChanged();
}
}
public string AdresseExtVille {
get => TypeResidence == false ? null : _adresseExtVille;
set {
_adresseExtVille = value;
OnPropertyChanged();
}
}
public DateTime DateCreation {
get => _dateCreation;
set {
_dateCreation = value;
OnPropertyChanged();
}
}
public DateTime DateModification {
get => _dateModification;
set {
_dateModification = value;
OnPropertyChanged();
}
}
[NotMapped]
public string TypeResidenceLabel {
get => TypeResidence == false ? "Principale" : "Secondaire";
}
[NotMapped]
public string Age {
get {
if(DateNaissance.HasValue) {
return (DateTime.Now.Year - DateNaissance.Value.Year).ToString();
}
return "";
}
set {
if(String.IsNullOrWhiteSpace(value)) {
DateNaissance = null;
} else {
try {
DateNaissance = new DateTime(DateTime.Now.Year - Int32.Parse(value), 1, 1);
} catch(Exception) { }
}
}
}
[NotMapped]
public int? AgeInt {
get {
if(DateNaissance.HasValue) {
return DateTime.Now.Year - DateNaissance.Value.Year;
}
return null;
}
}
[NotMapped]
public string AdresseCP => ModelContext.Getinstance().Preferences.Local[0].VilleCP;
[NotMapped]
public string AdresseVille => ModelContext.Getinstance().Preferences.Local[0].Ville;
[NotMapped]
public string AdressePrincipale {
get {
if(TypeResidence == false) {
return Adresse;
} else {
return AdresseExt;
}
}
}
[NotMapped]
public string AdressePrincipaleCP {
get {
if(TypeResidence == false) {
return AdresseCP;
} else {
return AdresseExtCP;
}
}
}
[NotMapped]
public string AdressePrincipaleVille {
get {
if(TypeResidence == false) {
return AdresseVille;
} else {
return AdresseExtVille;
}
}
}
[NotMapped]
public string AdresseSecondaire {
get {
if(TypeResidence == true) {
return Adresse;
} else {
return AdresseExt;
}
}
}
[NotMapped]
public string AdresseSecondaireCP {
get {
if(TypeResidence == true) {
return AdresseCP;
} else {
return AdresseExtCP;
}
}
}
[NotMapped]
public string AdresseSecondaireVille {
get {
if(TypeResidence == true) {
return AdresseVille;
} else {
return AdresseExtVille;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void Copyto(Citoyen citoyen) {
citoyen.Id = Id;
citoyen.Civilite = Civilite;
citoyen.Nom = Nom;
citoyen.NomNaissance = NomNaissance;
citoyen.Prenom = Prenom;
citoyen.DateNaissance = DateNaissance;
citoyen.Profession = Profession;
citoyen.TypeResidence = TypeResidence;
citoyen.Mail = Mail;
citoyen.Tel = Tel;
citoyen.TelPort = TelPort;
citoyen.Quartier = Quartier;
citoyen.Adresse = Adresse;
citoyen.AdresseBatiment = AdresseBatiment;
citoyen.AdresseNumeroBatiment = AdresseNumeroBatiment;
citoyen.AdresseExt = AdresseExt;
citoyen.AdresseExtCP = AdresseExtCP;
citoyen.AdresseExtVille = AdresseExtVille;
citoyen.DateCreation = DateCreation;
citoyen.DateModification = DateModification;
}
}
}