|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Text;
|
|
|
using System.Runtime.Serialization;
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
namespace Model
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// A user is an entity with a _name, a surname, mail, profilePict and a list of priority.
|
|
|
/// This user can login with an Id and a password
|
|
|
/// </summary>
|
|
|
[DataContract(Name = "user")]
|
|
|
public class User : IEquatable<User> , INotifyPropertyChanged
|
|
|
{
|
|
|
#region Private Attributes
|
|
|
|
|
|
[DataMember] private string name="";
|
|
|
[DataMember] private string surname="";
|
|
|
[DataMember] private string mail = "";
|
|
|
[DataMember] private string picture = "";
|
|
|
[DataMember] private string password = "";
|
|
|
[DataMember] private List<Priority> priorities;
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
#endregion
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
/// <summary>
|
|
|
/// Property to get Name of users and a setter
|
|
|
/// </summary>
|
|
|
/// <exception cref="ArgumentException" >Setter have Exception which is trigger when Name is null</exception>
|
|
|
public string Name
|
|
|
{
|
|
|
get { return name; }
|
|
|
set
|
|
|
{
|
|
|
|
|
|
name = value;
|
|
|
OnPropertyChanged();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Property to get Surname of users and a setter
|
|
|
/// </summary>
|
|
|
/// <exception cref="ArgumentException" >Setter have Exception which is trigger when Surname is null</exception>
|
|
|
public string Surname
|
|
|
{
|
|
|
get { return surname; }
|
|
|
set
|
|
|
{
|
|
|
|
|
|
surname = value;
|
|
|
OnPropertyChanged();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Property to get mail of users and a setter
|
|
|
/// </summary>
|
|
|
/// <exception cref="ArgumentException" >User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his
|
|
|
/// account creation.</exception>
|
|
|
public string Mail
|
|
|
{
|
|
|
get { return mail; }
|
|
|
private init
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
{
|
|
|
throw new ArgumentException("Impossible d'avoir un champ Email vide!");
|
|
|
}
|
|
|
mail = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string Password
|
|
|
{
|
|
|
get => password;
|
|
|
set => password = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// For now, we define the ProfilPict as a string which is "PhotoParDefaut"
|
|
|
/// when the value is null.
|
|
|
/// </summary>
|
|
|
public string ProfilPict
|
|
|
{
|
|
|
get => picture;
|
|
|
set => picture = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// This is the list of priorities specific tu the user. This list is initiate
|
|
|
/// by default. User could change it at will.
|
|
|
/// </summary>
|
|
|
|
|
|
public List<Priority> Priorities
|
|
|
{
|
|
|
get => priorities;
|
|
|
set=> priorities = value;
|
|
|
}
|
|
|
|
|
|
public override bool Equals(object? other)
|
|
|
{
|
|
|
if (other == null) return false;
|
|
|
if (other == this) return true;
|
|
|
return Equals(other);
|
|
|
}
|
|
|
|
|
|
public bool Equals(User? other)
|
|
|
{
|
|
|
if (other == null) return false;
|
|
|
return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail);
|
|
|
}
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
|
|
|
protected void OnPropertyChanged ([CallerMemberName] string? propertyName = null)
|
|
|
{
|
|
|
if (PropertyChanged != null)
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
}
|
|
|
|
|
|
public override string ToString()
|
|
|
{
|
|
|
return $"{Name} {Surname}";
|
|
|
}
|
|
|
|
|
|
[DataMember(Name = "passmgr")]
|
|
|
public IPasswordManager psswMgr { get; private set; }
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
/// <summary>
|
|
|
/// Construtors of user.
|
|
|
/// </summary>
|
|
|
/// <param name="name">The name of the user</param>
|
|
|
/// <param name="surname">The surname of the user</param>
|
|
|
/// <param name="mail">The user needs an email to login.</param>
|
|
|
/// <param name="password">The password of the new user.</param>
|
|
|
/// <param name="passwordManager">The password manager to manage the user password.</param>
|
|
|
public User(string name, string surname, string mail, string password, IPasswordManager passwordManager)
|
|
|
{
|
|
|
Name = name;
|
|
|
Surname = surname;
|
|
|
Mail = mail;
|
|
|
psswMgr = passwordManager;
|
|
|
Password = psswMgr.HashPassword(password);
|
|
|
priorities = new List<Priority> {
|
|
|
Priority.Gourmet,
|
|
|
Priority.Economic,
|
|
|
Priority.Fast,
|
|
|
Priority.Light,
|
|
|
Priority.Easy};
|
|
|
ProfilPict = picture;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// <inheritdoc cref="User.User"/>
|
|
|
/// </summary>
|
|
|
public User(string name, string surname, string mail, string password)
|
|
|
: this(name, surname,mail, password, new PasswordManager())
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// <inheritdoc cref="User.User"/>
|
|
|
/// </summary>
|
|
|
public User()
|
|
|
: this("John", "Doe", "truc@gmail.com", "mdp")
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// <inheritdoc cref="User.User"/>
|
|
|
/// </summary>
|
|
|
public User (User user)
|
|
|
{
|
|
|
Name = user.Name;
|
|
|
Surname = user.Surname;
|
|
|
Mail = user.Mail;
|
|
|
psswMgr = user.psswMgr;
|
|
|
Password = user.Password;
|
|
|
priorities = user.Priorities;
|
|
|
ProfilPict = user.ProfilPict;
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
|