private void AuditAddCard(int idCollection, int idGatherer, int idLanguage, ICardCount cardCount) { foreach (KeyValuePair <ICardCountKey, int> kv in cardCount) { AuditAddCard(idCollection, idGatherer, idLanguage, kv.Key, kv.Value); } }
public CardCount(ICardCount toCopy) { if (toCopy == null) { throw new ArgumentNullException(nameof(toCopy)); } foreach (KeyValuePair <ICardCountKey, int> kv in toCopy) { Add(kv.Key, kv.Value); } }
public void MoveCardToOtherCollection(ICardCollection collection, ICard card, IEdition edition, ILanguage language, ICardCount cardCount, ICardCollection collectionDestination) { if (cardCount == null) { return; } using (new WriterLock(_lock)) { int idGatherer = GetIdGatherer(card, edition); int idLanguage = language.Id; MoveCardToOtherCollection(collection, idGatherer, idLanguage, cardCount, collectionDestination); } }
public void MoveCardToOtherCollection(ICardCollection collection, int idGatherer, int idLanguage, ICardCount cardCount, ICardCollection collectionDestination) { if (cardCount == null) { return; } foreach (KeyValuePair <ICardCountKey, int> kv in cardCount) { MoveCardToOtherCollection(collection, idGatherer, idLanguage, kv.Value, kv.Key, collectionDestination); } }
public void InsertOrUpdateCardInCollection(int idCollection, int idGatherer, int idLanguage, ICardCount cardCount) { if (cardCount == null) { return; } using (new WriterLock(_lock)) { using (BatchMode()) { int countToAdd = cardCount.GetCount(CardCountKeys.Standard); int foilCountToAdd = cardCount.GetCount(CardCountKeys.Foil); int altArtCountToAdd = cardCount.GetCount(CardCountKeys.AltArt); int foilAltArtCountToAdd = cardCount.GetCount(CardCountKeys.FoilAltArt); ICardInCollectionCount cardInCollection = GetCardCollection(idCollection, idGatherer, idLanguage); if (cardInCollection == null) { //Insert new if (cardCount.Any(kv => kv.Value < 0) || cardCount.GetTotalCount() == 0) { return; } CardInCollectionCount newCardInCollectionCount = new CardInCollectionCount { IdCollection = idCollection, IdGatherer = idGatherer, Number = countToAdd, FoilNumber = foilCountToAdd, AltArtNumber = altArtCountToAdd, FoilAltArtNumber = foilAltArtCountToAdd, IdLanguage = idLanguage }; AddToDbAndUpdateReferential(newCardInCollectionCount, InsertInReferential); AuditAddCard(idCollection, idGatherer, idLanguage, cardCount); return; } //Update int newCount = countToAdd + cardInCollection.Number; int newFoilCount = foilCountToAdd + cardInCollection.FoilNumber; int newAltArtCountToAdd = altArtCountToAdd + cardInCollection.AltArtNumber; int newFoilAltArtCount = foilAltArtCountToAdd + cardInCollection.FoilAltArtNumber; if (newCount < 0 || newFoilCount < 0 || newAltArtCountToAdd < 0 || newFoilAltArtCount < 0) { return; } if (cardInCollection is not CardInCollectionCount updateCardInCollectionCount) { return; } if (newCount + newFoilCount + newAltArtCountToAdd + newFoilAltArtCount == 0) { RemoveFromDbAndUpdateReferential(updateCardInCollectionCount, RemoveFromReferential); AuditAddCard(idCollection, idGatherer, idLanguage, cardCount); return; } updateCardInCollectionCount.Number = newCount; updateCardInCollectionCount.FoilNumber = newFoilCount; updateCardInCollectionCount.AltArtNumber = newAltArtCountToAdd; updateCardInCollectionCount.FoilAltArtNumber = newFoilAltArtCount; using (IDbConnection cnx = _databaseConnection.GetMagicConnection()) { Mapper <CardInCollectionCount> .UpdateOne(cnx, updateCardInCollectionCount); } AuditAddCard(idCollection, idGatherer, idLanguage, cardCount); } } }
internal ImportExportCardInfo(int idGatherer, ICardCount cardCount, int idLanguage) { IdGatherer = idGatherer; IdLanguage = idLanguage; _cardCount = new CardCount(cardCount); }