private BuyBoxStatus UpdateItem(ILogService log,
                                        MarketType market,
                                        string marketplaceId,
                                        BuyBoxStatus dbExist,
                                        BuyBoxStatusDTO buyBoxInfo,
                                        DateTime when)
        {
            if (dbExist != null)
            {
                if (dbExist.Status == BuyBoxStatusCode.Win && buyBoxInfo.Status == BuyBoxStatusCode.NotWin)
                {
                    dbExist.LostWinnerDate = buyBoxInfo.CheckedDate;
                }

                dbExist.WinnerMerchantName = buyBoxInfo.WinnerMerchantName;

                if (dbExist.WinnerPrice != buyBoxInfo.WinnerPrice)
                {
                    log.Info("Price changed, ASIN=" + buyBoxInfo.ASIN + ", MarketplaceId=" + marketplaceId + ": " + dbExist.WinnerPrice + "->" + buyBoxInfo.WinnerPrice + " (win=" + buyBoxInfo.Status);

                    dbExist.WinnerPriceLastChangeValue = buyBoxInfo.WinnerPrice ?? 0 - dbExist.WinnerPrice ?? 0;
                    dbExist.WinnerPrice = buyBoxInfo.WinnerPrice;
                    dbExist.WinnerPriceLastChangeDate = when;
                }

                dbExist.Status      = buyBoxInfo.Status;
                dbExist.CheckedDate = buyBoxInfo.CheckedDate;
            }
            else
            {
                dbExist      = new BuyBoxStatus();
                dbExist.ASIN = buyBoxInfo.ASIN;

                dbExist.Market        = (int)market;
                dbExist.MarketplaceId = marketplaceId;

                if (dbExist.Status == BuyBoxStatusCode.Win && buyBoxInfo.Status == BuyBoxStatusCode.NotWin)
                {
                    dbExist.LostWinnerDate = buyBoxInfo.CheckedDate;
                }

                dbExist.WinnerMerchantName = buyBoxInfo.WinnerMerchantName;

                dbExist.WinnerPrice = buyBoxInfo.WinnerPrice;
                dbExist.WinnerPriceLastChangeDate = when;

                dbExist.Status      = buyBoxInfo.Status;
                dbExist.CheckedDate = buyBoxInfo.CheckedDate;

                Add(dbExist);

                return(dbExist);
            }

            return(null);
        }
        public void Update(ILogService log,
                           ITime time,
                           BuyBoxStatusDTO buyBoxInfo,
                           MarketType market,
                           string marketplaceId)
        {
            var dbExist = GetAll().FirstOrDefault(b => b.ASIN == buyBoxInfo.ASIN &&
                                                  b.Market == (int)market &&
                                                  b.MarketplaceId == marketplaceId);

            UpdateItem(log, market, marketplaceId, dbExist, buyBoxInfo, time.GetAppNowTime());

            unitOfWork.Commit();
        }