Пример #1
0
 public void When(CarProduced e)
 {
     foreach (var part in e.Parts)
     {
         Change(part.Name, -part.Quantity);
     }
 }
Пример #2
0
        public static string Message(CarProduced e)
        {
            var builder = new StringBuilder();
            builder.AppendFormat("produce car {0}:", e.CarModel).AppendLine();
            foreach (var carPart in e.Parts)
                builder.AppendFormat("     {0} {1} pcs", carPart.Name, carPart.Quantity).AppendLine();

            return builder.ToString();

        }
Пример #3
0
        public static string Message(CarProduced e)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("produce car {0}:", e.CarModel).AppendLine();
            foreach (var carPart in e.Parts)
            {
                builder.AppendFormat("     {0} {1} pcs", carPart.Name, carPart.Quantity).AppendLine();
            }

            return(builder.ToString());
        }
Пример #4
0
        public void When(CarProduced theEvent)
        {
            CreatedCars.Add(theEvent.CarModel);

            foreach (var carPart in theEvent.Parts)
            {
                var removed = carPart.Quantity;

                var quantitied = GetNumberOfAvailablePartsQuantity(carPart.Name);
                if (quantitied > 0)
                    _availableParts[carPart.Name] = quantitied > removed ? quantitied - removed : 0;
            }

            var emptyPartKeys = _availableParts.Where(x => x.Value == 0).Select(x => x.Key).ToList();

            foreach (var emptyPartKey in emptyPartKeys)
            {
                _availableParts.Remove(emptyPartKey);
            }

            // Rule: an employee can only produce one car per day
            // so remember who just did it

            EmployeesWhoHaveProducedACarToday.Add(theEvent.EmployeeName);
        }