Restructuration
This commit is contained in:
240
Model/Citoyen.cs
Normal file
240
Model/Citoyen.cs
Normal file
@ -0,0 +1,240 @@
|
||||
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 _adresseNumero;
|
||||
private string _adresseRue;
|
||||
private string _adresseBatiment;
|
||||
private string _adresseExtNumero;
|
||||
private string _adresseExtRue;
|
||||
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) {
|
||||
AdresseExtNumero = null;
|
||||
AdresseExtRue = 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 AdresseNumero {
|
||||
get => _adresseNumero;
|
||||
set {
|
||||
_adresseNumero = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string AdresseRue {
|
||||
get => _adresseRue;
|
||||
set {
|
||||
_adresseRue = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string AdresseBatiment {
|
||||
get => _adresseBatiment;
|
||||
set {
|
||||
_adresseBatiment = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string AdresseExtNumero {
|
||||
get => TypeResidence == false ? null : _adresseExtNumero;
|
||||
set {
|
||||
_adresseExtNumero = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string AdresseExtRue {
|
||||
get => TypeResidence == false ? null : _adresseExtRue;
|
||||
set {
|
||||
_adresseExtRue = 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 string AdresseCP => ModelContext.Getinstance().Preferences.Local[0].VilleCP;
|
||||
|
||||
[NotMapped]
|
||||
public string AdresseVille => ModelContext.Getinstance().Preferences.Local[0].Ville;
|
||||
|
||||
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.AdresseNumero = AdresseNumero;
|
||||
citoyen.AdresseRue = AdresseRue;
|
||||
citoyen.AdresseBatiment = AdresseBatiment;
|
||||
citoyen.AdresseExtNumero = AdresseExtNumero;
|
||||
citoyen.AdresseExtRue = AdresseExtRue;
|
||||
citoyen.AdresseExtCP = AdresseExtCP;
|
||||
citoyen.AdresseExtVille = AdresseExtVille;
|
||||
citoyen.DateCreation = DateCreation;
|
||||
citoyen.DateModification = DateModification;
|
||||
}
|
||||
}
|
||||
}
|
25
Model/ModelContext.cs
Normal file
25
Model/ModelContext.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.IO;
|
||||
|
||||
namespace Hermes.Model {
|
||||
public class ModelContext : DbContext {
|
||||
private static ModelContext instance = new ModelContext();
|
||||
|
||||
public static ModelContext Getinstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ModelContext()
|
||||
: base("Data Source=" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hermes.sdf")) {
|
||||
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ModelContext, Migrations.Configuration>());
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Citoyen> CitoyenSet { get; set; }
|
||||
public virtual DbSet<Preferences> Preferences { get; set; }
|
||||
}
|
||||
}
|
10
Model/Preferences.cs
Normal file
10
Model/Preferences.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Hermes.Model {
|
||||
public class Preferences {
|
||||
public int Id { get; set; }
|
||||
public string VilleCP { get; set; }
|
||||
public string Ville { get; set; }
|
||||
public string SmsApiKey { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user