public void Save(MagicCard magicCard)
 {
     _connection
         .GetConnection()
         .Execute(
             "INSERT INTO Prices ([BotGroupId],[CardId],[BuyPrice],[SellPrice],[OwnedAmount]) " +
             "VALUES(@BotGroupId, @Id, @BuyPrice, @SellPrice, @OwnedAmount) ",
             magicCard,
             _connection.GetTransaction());
 }
 public MagicCard Get(MagicCard card)
 {
     return _connection.GetConnection().Query<MagicCard>(
         "SELECT CardId as Id, c.CardName as Name, c.CardSet as [Set], c.Premium, 0 as BuyPrice, 0 as SellPrice, " +
         "c.CardRarity as Rarity, c.MtgoCardId as MtgoId, 0 as OwnedAmount, c.CardSetNumber, @BotId as BotId, @BotGroupId as BotGroupId " +
         "FROM Cards c " +
         "WHERE c.MtgoCardId = @MtgoId OR (c.CardName = @Name AND c.CardSet = @Set AND c.Premium = @Premium)",
         card,
         _connection.GetTransaction())
         .Single();
 }
 public void Update(MagicCard magicCard)
 {
     _connection
         .GetConnection()
         .Execute(
             "UPDATE Prices " +
             "SET BuyPrice = @BuyPrice, " +
             "SellPrice = @SellPrice, " +
             "OwnedAmount = @OwnedAmount " +
             "WHERE BotGroupId = @BotGroupId " +
             "AND CardId = @Id",
             magicCard,
             _connection.GetTransaction());
 }
        public void WriteToDatabase()
        {
            using (var connection = IoC.Resolve<IConnection>())
            {
                connection.BeginTransaction();

                foreach (var magicCard in CollectionCards)
                {
                    var dbCard = _magicCardRepository.Get(magicCard);

                    if (dbCard == null)
                    {
                        var card = new MagicCard(magicCard.Name, magicCard.Set, magicCard.Premium, magicCard.Rarity)
                            {BuyPrice = -1, SellPrice = 999, OwnedAmount = 0};

                        _magicCardRepository.Save(card);
                        _priceRepository.Save(card);
                    }
                    else
                    {
                        _magicCardRepository.Update(magicCard);
                    }
                }

                connection.CommitTransaction();
            }
        }
 public void Update(MagicCard magicCard)
 {
     _connection
         .GetConnection()
         .Execute(
             "UPDATE Cards " +
             "SET CardName = @Name, " +
             "CardSet = @Set, " +
             "CardRarity = @Rarity, " +
             "Premium = @Premium, " +
             "MtgoCardId = @MtgoId " +
             "WHERE CardId = @Id ",
             magicCard,
             _connection.GetTransaction());
 }
 public void Save(MagicCard magicCard)
 {
     _connection
         .GetConnection()
         .Execute(
             "INSERT INTO Cards ([CardName],[CardSet],[CardRarity],[Premium],[MtgoCardId],[CardSetNumber]) " +
             "VALUES(@Name, @Set, @Rarity, @Premium, @MtgoId, @CardSetNumber) ",
             magicCard,
             _connection.GetTransaction());
 }