using Model.Dice.Faces; using System; using System.Collections.Generic; using System.Linq; namespace Model.Dice { public class DieManager : IManager>>>> { private readonly Dictionary>>> diceGroups = new(); public KeyValuePair>>> Add(KeyValuePair>>> toAdd) { // on trim la clé d'abord diceGroups.Add(toAdd.Key.Trim(), toAdd.Value); return toAdd; } public IEnumerable>>>> GetAll() { return diceGroups.AsEnumerable(); } public KeyValuePair>>> GetOneByName(string name) { // les groupes de dés nommés : // ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu" return new KeyValuePair>>>(name, diceGroups[name]); } public void Remove(KeyValuePair>>> 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>>> Update(KeyValuePair>>> before, KeyValuePair>>> 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>>> IManager>>>>.GetAll() { throw new NotImplementedException(); } KeyValuePair>>> IManager>>>>.GetOneByName(string name) { throw new NotImplementedException(); } */ } }