Exemple #1
0
        /// <summary>
        /// Save <see cref="OzonProductPriceHistory"/> data into DB
        /// </summary>
        /// <param name="productHistoryRecord"></param>
        /// <returns></returns>
        public async Task <int> SaveProductHistoryAsync(OzonProductPriceHistory productHistoryRecord)
        {
            if (productHistoryRecord == null)
            {
                logger.Debug($"{nameof(productHistoryRecord)} is null!");

                return(0);
            }

            using (var client = new SqliteContext(_connectionString))
            {
                if (productHistoryRecord.Id == 0)
                {
                    client.OzonProductPriceHistories.Add(productHistoryRecord);
                    await client.SaveChangesAsync();
                }
                else
                {
                    client.Update(productHistoryRecord);
                    await client.SaveChangesAsync();
                }

                return(productHistoryRecord.Id);
            }
        }
        private static OzonProductPriceHistory MapProductIntoOzonProductHistory(Product product, DateTime moment)
        {
            var ozonProductPriceHistory = new OzonProductPriceHistory();

            ozonProductPriceHistory.Id               = 0;
            ozonProductPriceHistory.ProductId        = product.Id;
            ozonProductPriceHistory.Date             = moment;
            ozonProductPriceHistory.OfferName        = product.OfferName;
            ozonProductPriceHistory.OfferMessageText = product.OfferMessageText;
            ozonProductPriceHistory.PriceBase        = product.PriceBase;
            ozonProductPriceHistory.Price            = product.Price;
            ozonProductPriceHistory.Discount         = product.Discount;
            ozonProductPriceHistory.PricePremium     = product.PricePremium;
            ozonProductPriceHistory.IsAvailable      = product.IsAvailable;

            return(ozonProductPriceHistory);
        }