Esempio n. 1
0
        public CardPrice FindAndModifyCardPrice(CardPrice cardPrice, bool upsert = true)
        {
            if (cardPrice == null)
            {
                throw new ArgumentNullException("cardPrice");
            }

            var cardPriceCollection = this.mDatabase.GetCollection <CardPrice>(cCardPriceCollectionName);

            // Query for this card
            var cardQuery = Query.And(
                Query.EQ("name", cardPrice.Name),
                Query.EQ("setCode", cardPrice.SetCode),
                Query.EQ("multiverseId", cardPrice.MultiverseId)
                );

            var cardSoryBy = SortBy.Descending("name");

            // Update document
            var cardUpdate = Update
                             .Set("url", cardPrice.Url)
                             .Set("name", cardPrice.Name)
                             .Set("searchName", cardPrice.SearchName)
                             .Set("lastUpdated", cardPrice.LastUpdated)
                             .Set("setCode", cardPrice.SetCode)
                             .Set("setCodeAlternate", cardPrice.SetCodeAlternate)
                             .Set("priceDiff", cardPrice.PriceDiff)
                             .Set("priceDiffValue", cardPrice.PriceDiffValue)
                             .Set("priceMid", cardPrice.PriceMid)
                             .Set("priceLow", cardPrice.PriceLow)
                             .Set("priceFoil", cardPrice.PriceFoil)
                             .Set("multiverseId", cardPrice.MultiverseId)
                             .Set("imageUrl", cardPrice.ImageUrl);

            // Find and modify document. If document doesnt exist, insert it
            FindAndModifyArgs findModifyArgs = new FindAndModifyArgs();

            findModifyArgs.SortBy          = cardSoryBy;
            findModifyArgs.Query           = cardQuery;
            findModifyArgs.Upsert          = true;
            findModifyArgs.Update          = cardUpdate;
            findModifyArgs.VersionReturned = FindAndModifyDocumentVersion.Modified;

            var cardResult   = cardPriceCollection.FindAndModify(findModifyArgs);
            var cardModified = cardResult.GetModifiedDocumentAs <CardPrice>();

            return(cardModified);
        }
        public bool RemoveCardPrice(CardPrice cardPrice)
        {
            if (cardPrice == null)
            {
                throw new ArgumentNullException("cardPrice");
            }

            var cardPriceCollection = this.mDatabase.GetCollection <CardPrice>(cCardPriceCollectionName);

            var query = Query <CardPrice> .EQ(c => c.Id, cardPrice.Id);

            var removeResult = cardPriceCollection.Remove(query);

            if (removeResult.Response["ok"] == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }