Ejemplo n.º 1
0
        public void InsertNewCardEdition(int idGatherer, int idEdition, string name, string partName, string rarity, string url)
        {
            using (new WriterLock(_lock))
            {
                int idRarity = GetRarityId(rarity);
                int idCard   = GetCard(name, partName).Id;

                if (idGatherer == 0 || idEdition <= 0)
                {
                    throw new ApplicationDbException("Data are not filled correctedly");
                }

                if (GetCardEdition(idGatherer) != null)
                {
                    return;
                }

                CardEdition cardEdition = new CardEdition
                {
                    IdCard     = idCard,
                    IdGatherer = idGatherer,
                    IdEdition  = idEdition,
                    IdRarity   = idRarity,
                    Url        = url
                };

                AddToDbAndUpdateReferential(cardEdition, InsertInReferential);
            }
        }
Ejemplo n.º 2
0
        public int InsertNewCardEditionWithFakeGathererId(int idEdition, int idCard, int idRarity, string url)
        {
            using (new WriterLock(_lock))
            {
                IEdition edition = _editions.FirstOrDefault(e => e.Id == idEdition);
                IRarity  rarity  = _rarities.Values.FirstOrDefault(r => r.Id == idRarity);
                ICard    card    = _cardsbyId.GetOrDefault(idCard);

                if (rarity == null || card == null || edition == null)
                {
                    throw new ApplicationDbException("Data are not filled correctedly");
                }
                if (!edition.IsNoneGatherer())
                {
                    throw new ApplicationDbException("InsertNewCardEditionWithFakeGathererId could only used for NoneGatherer edition");
                }
                int existingIdGatherer = GetIdGatherer(card, edition);
                if (existingIdGatherer != 0)
                {
                    // could have been inserted by another thread
                    return(existingIdGatherer);
                }

                int idGatherer = GetNextFakeGathererId();

                CardEdition cardEdition = new CardEdition
                {
                    IdCard     = idCard,
                    IdGatherer = idGatherer,
                    IdEdition  = idEdition,
                    IdRarity   = idRarity,
                    Url        = url
                };

                AddToDbAndUpdateReferential(cardEdition, InsertInReferential);

                return(idGatherer);
            }
        }