You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.6 KiB
138 lines
4.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Biblioteque_de_Class
|
|
{
|
|
public class Note
|
|
{
|
|
private string Name
|
|
{
|
|
get { return Name; }
|
|
set { if (value == null) { Name = "Unnamed Note"; } else { Name = value; } }
|
|
}
|
|
|
|
///private string Text { get; set; } Attribut pour le texte de la note
|
|
private string LogoPath
|
|
{
|
|
get { return LogoPath; }
|
|
set { if (value == null) { LogoPath = "PATH TO DEFAULT LOGO"; } else { LogoPath = value; } }
|
|
}
|
|
|
|
private DateOnly CreationDate { get; }
|
|
private DateOnly ModificationDate { get; set; }
|
|
private List<NoteImage> ImageList;
|
|
private List<string> TextLineList;
|
|
private List<User> Collaborators;
|
|
private List<User> Editors;
|
|
private User Owner;
|
|
|
|
public Note(string name, string logoPath, User owner)
|
|
{
|
|
Name = name;
|
|
LogoPath = logoPath;
|
|
CreationDate = DateOnly.FromDateTime(DateTime.Now);
|
|
ModificationDate = DateOnly.FromDateTime(DateTime.Now);
|
|
ImageList = new List<NoteImage>();
|
|
TextLineList = new List<string>();
|
|
Collaborators = new List<User>();
|
|
Editors = new List<User>();
|
|
|
|
Owner = owner;
|
|
}
|
|
|
|
public string GetName() { return Name; }
|
|
public string GetLogoPath() { return LogoPath; }
|
|
public DateOnly GetCreationDate() { return CreationDate; }
|
|
public DateOnly GetModificationDate() { return ModificationDate; }
|
|
public List<NoteImage> GetImageList() { return ImageList; }
|
|
public List<string> GetTextLineList() { return TextLineList; }
|
|
public List<User> GetCollaborators() { return Collaborators; }
|
|
public List<User> GetEditors() { return Editors; }
|
|
public User GetOwner() { return Owner; }
|
|
|
|
public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}\nNumber of lines: {TextLineList.Count()}";
|
|
|
|
public void SetName(string name) { Name = name; }
|
|
public void SetLogoPath(string logoPath) { LogoPath = logoPath; }
|
|
public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
|
|
|
|
/// <summary>
|
|
/// vérifier si l'utilisateur est le propriétaire de la note
|
|
/// </summary>
|
|
public bool VerifyOwner(User user)
|
|
{
|
|
return user == Owner;
|
|
}
|
|
|
|
public void AddImage(string imageLink, string position)
|
|
{
|
|
foreach (NoteImage image in ImageList)
|
|
{
|
|
if (image.GetImageLink() == imageLink)
|
|
{
|
|
/// Do something
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveImage(string image)
|
|
{
|
|
/// Need a new data structure to store images
|
|
}
|
|
|
|
/// <summary>
|
|
/// vérifier si l'utilisateur est un éditeur de la note
|
|
/// </summary>
|
|
public bool VerifyPrivilege(User user)
|
|
{
|
|
if (Editors.Contains(user))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("User is not an editor");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ajouter un utilisateur en tant que coopérateur
|
|
/// </summary>
|
|
public void AddCollaborator(User owner, User user)
|
|
{
|
|
if (VerifyOwner(owner)) { Collaborators.Add(user); }
|
|
else { throw new Exception("User is not the owner"); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// supprimer un utilisateur en tant que coopérateur
|
|
/// </summary>
|
|
public void RemoveCollaborator(User owner, User user)
|
|
{
|
|
if (VerifyOwner(owner)) { Collaborators.Remove(user); }
|
|
else { throw new Exception("User is not the owner"); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// passer un coopérateur en tant qu'éditeur
|
|
/// </summary>
|
|
public void AddEditor(User owner, User user)
|
|
{
|
|
if (VerifyOwner(owner)) { Editors.Add(user); }
|
|
else { throw new Exception("User is not the owner"); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// supprimer un coopérateur de la liste des éditeurs
|
|
/// </summary>
|
|
public void RemoveEditor(User owner, User user)
|
|
{
|
|
if (VerifyOwner(owner)) { Editors.Remove(user); }
|
|
else { throw new Exception("User is not the owner"); }
|
|
}
|
|
}
|
|
}
|