public void Execute(string[] jsons) { IValidationResult[] results = _validataCards.Execute(jsons); if (jsons.Length != results.Length) { throw new InvalidValidationResultCountException(); } if (results.Any(_ => !_.Valid)) { PublishErrorMessage(results); } else { int newVersionNumber = _incrementVersionNumber.Execute(); List <string> cardIDs = new List <string>(); foreach (IValidationResult validationResult in results) { cardIDs.Add(validationResult.ValidCardData.CardID); validationResult.ValidCardData.VersionAdded = newVersionNumber; if (_cardGateway.HasCard(validationResult.ValidCardData.CardID)) { _cardGateway.UpdateCard(validationResult.ValidCardData); RemoveFromOldPack(validationResult); } else { _cardGateway.AddCard(validationResult.ValidCardData); } } _packGateway.SetCards(cardIDs.ToArray(), newVersionNumber); } }
public void Execute(string json) { IValidationResult validationResult = _validCardData.Execute(json); if (!validationResult.Valid) { return; } if (_cardGateway.HasCard(validationResult.ValidCardData.CardID)) { RemoveCardIDFromOldPack(validationResult); validationResult.ValidCardData.VersionAdded = _incrementVersionNumber.Execute(); AddNewPack(validationResult); UpdateCardWithNewPackNumber(validationResult); } else { validationResult.ValidCardData.VersionAdded = _incrementVersionNumber.Execute(); AddNewPack(validationResult); _cardGateway.AddCard(validationResult.ValidCardData); } }