using Model.Dice.Faces; using System; using System.Collections.Generic; using System.Linq; namespace Model.Dice { public class DieManager : IManager,object>>>> { private readonly Dictionary,object>>> diceGroups = new(); public KeyValuePair,object>>> Add(KeyValuePair,object>>> toAdd) { // on trim la clé d'abord diceGroups.Add(toAdd.Key.Trim(), toAdd.Value); return toAdd; } public IEnumerable,object>>>> GetAll() { return diceGroups.AsEnumerable(); } public KeyValuePair,object>>> GetOneByName(string name) { // les groupes de dés nommés : // ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu" return new KeyValuePair,object>>>(name, diceGroups[name]); } public void Remove(KeyValuePair,object>>> toRemove) { diceGroups.Remove(toRemove.Key); } /*public void Remove(KeyValuePair, object>>> toRemove) { throw new NotImplementedException(); } public void Remove(KeyValuePair, object>>> toRemove) { throw new NotImplementedException(); }*/ public KeyValuePair,object>>> Update(KeyValuePair,object>>> before, KeyValuePair,object>>> after) { // pas autorisé de changer les dés, juste le nom if (!before.Value.Equals(after.Value)) { if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key)) { throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty"); } diceGroups.Remove(before.Key); diceGroups.Add(after.Key, after.Value); return after; } return before; } IEnumerable, object>>>> IManager, object>>>>.GetAll() { throw new NotImplementedException(); } KeyValuePair, object>>> IManager, object>>>>.GetOneByName(string name) { throw new NotImplementedException(); } } }