Пример #1
0
        public static void AddProducts(JsonReport jsonReport)
        {
            var productReports = Database.GetCollection <ProductReportJson>("ProductReports");
            var productList    = productReports.AsQueryable <ProductReportJson>();
            var list           = jsonReport.ProductReportsToList();

            foreach (var product in list)
            {
                int countWords = productList.AsQueryable <ProductReportJson>().Where(w => w.ProductId == product.ProductId).Count();
                var searched   = productReports.AsQueryable <ProductReportJson>().FirstOrDefault(w => w.Name == product.Name.ToString());
                if (countWords > 0 && searched.Incomes != product.Incomes)
                {
                    UpdateProduct(product, productReports);
                }
                else if (countWords == 0)
                {
                    productReports.Insert <ProductReportJson>(product);
                }
            }
        }