public static void Main()
        {
            var sqlDB = new DatabaseContext();
            var mongoDB = GetDatabase(DatabaseHost, DatabaseName);

            var makerIDsMongo = MigrateMakersTable(sqlDB, mongoDB);
            var modelIDsMongo = MigrateModelsTable(sqlDB, mongoDB);

            sqlDB.SaveChanges();

            MigrateLaptopsTable(sqlDB, mongoDB, makerIDsMongo, modelIDsMongo);

            sqlDB.SaveChanges();
        }
        private static ICollection<string> MigrateModelsTable(DatabaseContext sqlDB, MongoDatabase mongoDB)
        {
            ICollection<string> modelIDsMongo = new HashSet<string>();
            var modelsMongo = mongoDB.GetCollection<Models.Mongo.Model>("Models").FindAll().Select(m => m).ToList();

            foreach (var Order in modelsMongo)
            {
                modelIDsMongo.Add(Order.Id);

                var newModel = new Models.EF.Model(Order.Name, Order.CPU, Order.RAM, Order.HDD);
                sqlDB.Models.Add(newModel);
            }

            return modelIDsMongo;
        }
        private static ICollection<string> MigrateMakersTable(DatabaseContext sqlDB, MongoDatabase mongoDB)
        {
            ICollection<string> makerIDsMongo = new HashSet<string>();
            var makersMongo = mongoDB.GetCollection<Models.Mongo.Maker>("Makers").FindAll().Select(m => m).ToList();

            foreach (var maker in makersMongo)
            {
                makerIDsMongo.Add(maker.Id);

                var newMaker = new Models.EF.Maker(maker.Name, maker.Phone, maker.Email);
                sqlDB.Makers.Add(newMaker);
            }

            return makerIDsMongo;
        }
        private static void MigrateLaptopsTable(DatabaseContext sqlDB, MongoDatabase mongoDB, ICollection<string> makerIDsMongo, ICollection<string> modelIDsMongo)
        {
            var laptopsMongo = mongoDB.GetCollection<Models.Mongo.Laptop>("Laptops").FindAll().Select(l => l).ToList();
            var makerIDs = makerIDsMongo.ToList();
            var modelIDs = modelIDsMongo.ToList();

            foreach (var laptop in laptopsMongo)
            {
                var makerIndexID = makerIDs.FindIndex(l => l == laptop.MakerID);
                var modelIndexID = modelIDs.FindIndex(l => l == laptop.ModelID);
                var newLaptop = new Models.EF.Laptop(laptop.Price, laptop.Quantity);
                newLaptop.Maker = sqlDB.Makers.First(m => m.Id == makerIndexID + 1);
                newLaptop.Model = sqlDB.Models.First(m => m.Id == modelIndexID + 1);
                sqlDB.Laptops.Add(newLaptop);
            }
        }
        public static List<MakersLaptops> GetData()
        {
            using (var db = new DatabaseContext())
            {
                var laptops = db.Laptops
                  .Select(l => new MakersLaptops
                  {
                      MakerId = l.MakerID,
                      MakerName = l.Maker.Name,
                      Price = l.Price,
                      Quantity = l.Quantity
                  })
                  .OrderBy(id => id.MakerId)
                  .ToList();

                return laptops;

            }
        }
        private void FillComputerReportsTableData(PdfPTable table, DatabaseContext db)
        {
            var computersReports = db.Laptops
                .Select(c =>
                    new
                    {
                        ManufacturerColumnHeader = c.Maker.Name,
                        ModelColumnHeader = c.Model,
                        PriceColumnHeader = c.Price
                    })
                .ToList();

            foreach (var computer in computersReports)
            {
                table.AddCell(computer.ManufacturerColumnHeader);
                table.AddCell(computer.ModelColumnHeader.Name);
                table.AddCell(computer.PriceColumnHeader + " $");
            }
        }
        static void Main(string[] args)
        {
            using (var db = new DatabaseContext())
            {
                int i = 1;
                ExcelReportReadingProvider.ReadZippedReports("../../../ExcelSampleData/GraphicsCardsReports.zip", "../../../ExcelSampleData/reports", x =>
                {
                    Console.WriteLine("Loading report row {4}: {0}GB  {1}Ghz  {2}$  {3}", x[0], x[1], x[2], x[3], i++);
                    db.GraphicsCards.Add(new GraphicsCard()
                    {
                        MemorySize = decimal.Parse(x[0].ToString()),
                        ClockSpeed = decimal.Parse(x[1].ToString()),
                        Price = decimal.Parse(x[2].ToString()),
                        Manufacturer = x[3].ToString()
                    });

                });

                db.SaveChanges();
            }
        }
        public void GenerateComputersReports(string filePath, string fileName, DatabaseContext db)
        {
            fileName = MakeUniqueFileName(fileName);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            var document = new Document(PageSize.A4, 50, 50, 25, 25);
            var output = new FileStream(filePath + fileName, FileMode.Create, FileAccess.Write);
            var writer = PdfWriter.GetInstance(document, output);

            PdfPTable table = this.GetReportsTable();
            this.AddComputerReportsTableHeader(table);
            this.AddComputerReportsTableColumns(table);
            this.FillComputerReportsTableData(table, db);

            document.Open();
            document.Add(table);
            document.Close();
        }
        public static void ProcessToMssql(IEnumerable<Product> products)
        {
            var db = new DatabaseContext();

            foreach (var product in products)
            {
                foreach (var order in product.Orders)
                {
                    var orderToAdd = new Models.EF.Order(order.Month, order.Count);

                    var modelOfOrder = db.Models
                                        .Where(m => m.Name == product.ModelName)
                                        .FirstOrDefault();

                    orderToAdd.Model = modelOfOrder;

                    db.Orders.Add(orderToAdd);
                }
            }

            db.SaveChanges();
        }
        public static void Main()
        {
            Console.WriteLine("Extracting information from database and saving it to xml report...");

            using (var db = new DatabaseContext())
            {
                // Query to sql server. Join three tables - Models, Laptops and Makers to take whole information about laptop.
                var laptops =
                    from model in db.Models
                    join laptop in db.Laptops
                    on model.Id equals laptop.Id
                    join maker in db.Makers
                    on laptop.Id equals maker.Id
                    select new
                    {
                        MakerName = maker.Name,
                        ModelName = model.Name,
                        Cpu = model.CPU,
                        Hdd = model.HDD,
                        Ram = model.RAM
                    };

                // Create class types elements - high, medium, low
                XmlDocument doc = new XmlDocument();
                XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                XmlElement root = doc.DocumentElement;
                doc.InsertBefore(xmlDeclaration, root);

                XmlElement classTypes = doc.CreateElement("classTypes");
                doc.AppendChild(classTypes);

                XmlElement highClass = doc.CreateElement("highClass");
                classTypes.AppendChild(highClass);

                XmlElement mediumClass = doc.CreateElement("mediumClass");
                classTypes.AppendChild(mediumClass);

                XmlElement lowClass = doc.CreateElement("lowClass");
                classTypes.AppendChild(lowClass);

                foreach (var laptop in laptops)
                {
                    // Create laptop elements
                    XmlElement laptopItem = doc.CreateElement("laptop");

                    XmlElement maker = doc.CreateElement("maker");
                    XmlText makerName = doc.CreateTextNode(laptop.MakerName);
                    maker.AppendChild(makerName);
                    laptopItem.AppendChild(maker);

                    XmlElement model = doc.CreateElement("model");
                    XmlText modelName = doc.CreateTextNode(laptop.ModelName);
                    model.AppendChild(modelName);
                    laptopItem.AppendChild(model);

                    XmlElement parameters = doc.CreateElement("parameters");
                    laptopItem.AppendChild(parameters);

                    XmlElement cpu = doc.CreateElement("cpu");
                    XmlText cpuText = doc.CreateTextNode(laptop.Cpu);
                    cpu.AppendChild(cpuText);
                    parameters.AppendChild(cpu);

                    XmlElement ram = doc.CreateElement("ram");
                    XmlText ramText = doc.CreateTextNode(laptop.Ram.ToString());
                    ram.AppendChild(ramText);
                    parameters.AppendChild(ram);

                    XmlElement hdd = doc.CreateElement("hdd");
                    XmlText hddText = doc.CreateTextNode(laptop.Hdd.ToString());
                    hdd.AppendChild(hddText);
                    parameters.AppendChild(hdd);

                    if (laptop.Cpu.Contains("i7"))
                    {
                        highClass.AppendChild(laptopItem);

                    }
                    else if (laptop.Cpu.Contains("i5"))
                    {
                        mediumClass.AppendChild(laptopItem);
                    }
                    else if (laptop.Cpu.Contains("i3"))
                    {
                        lowClass.AppendChild(laptopItem);
                    }
                }

                doc.Save("../../classTypesOfLaptopReport.xml");
            }
        }