♻️ Rename DieManager to DiceGroupManager #126
Merged
alexis.drai
merged 1 commits from rename-diemanager
into main
3 years ago
@ -1,87 +1,87 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Model.Dice
|
namespace Model.Dice
|
||||||
{
|
{
|
||||||
public class DieManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
|
public class DiceGroupManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
|
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
|
||||||
|
|
||||||
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
|
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(toAdd.Key))
|
if (string.IsNullOrWhiteSpace(toAdd.Key))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
|
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (diceGroups.Contains(toAdd))
|
if (diceGroups.Contains(toAdd))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("this username is already taken", nameof(toAdd));
|
throw new ArgumentException("this username is already taken", nameof(toAdd));
|
||||||
}
|
}
|
||||||
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
|
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
|
||||||
return toAdd;
|
return toAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
|
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
|
||||||
{
|
{
|
||||||
return diceGroups.AsEnumerable();
|
return diceGroups.AsEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
|
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
|
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
|
||||||
{
|
{
|
||||||
// les groupes de dés nommés :
|
// les groupes de dés nommés :
|
||||||
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
|
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
|
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
|
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
|
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
|
||||||
{
|
{
|
||||||
if (toRemove.Key is null)
|
if (toRemove.Key is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
|
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
diceGroups.Remove(toRemove.Key);
|
diceGroups.Remove(toRemove.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates a (string, IEnumerable-of-Die) couple. only the name can be updated
|
/// updates a (string, IEnumerable-of-Die) couple. only the name can be updated
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="before">original couple</param>
|
/// <param name="before">original couple</param>
|
||||||
/// <param name="after">new couple</param>
|
/// <param name="after">new couple</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ArgumentException"></exception>
|
/// <exception cref="ArgumentException"></exception>
|
||||||
/// <exception cref="ArgumentNullException"></exception>
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
|
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
|
||||||
{
|
{
|
||||||
// pas autorisé de changer les dés, juste le nom
|
// pas autorisé de changer les dés, juste le nom
|
||||||
if (!before.Value.Equals(after.Value))
|
if (!before.Value.Equals(after.Value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
|
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
|
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
|
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
|
||||||
}
|
}
|
||||||
diceGroups.Remove(before.Key);
|
diceGroups.Remove(before.Key);
|
||||||
diceGroups.Add(after.Key, after.Value);
|
diceGroups.Add(after.Key, after.Value);
|
||||||
return after;
|
return after;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue