Exemple #1
0
        public IEnumerable <DenominationModel> Restock(IEnumerable <DenominationModel> stock)
        {
            lock (_lock)
            {
                var currentDenoms = GetDenominations().ToDictionary(s => s.Denomination);

                foreach (var entry in stock)
                {
                    if (entry.Count < 0)
                    {
                        throw new InvalidAtmOperationException($"Denomination {entry.Denomination} can not be stocked with a negative count.");
                    }

                    if (currentDenoms.TryGetValue(entry.Denomination, out DenominationModel denom))
                    {
                        denom.Count += entry.Count;
                    }
                    else
                    {
                        throw new InvalidAtmOperationException($"Denomination {entry.Denomination} is not a valid value.");
                    }
                }

                var finalDenoms = currentDenoms.Values.ToList();

                _dao.Update(finalDenoms);

                return(finalDenoms);
            }
        }