private void FillAutopartsReportsTableData(PdfPTable table, AutopartsDbContext db)
        {
            var computersReports = db.AutoParts
                .Select(c =>
                    new
                    {
                        ModelColumnHeader = c.Name,
                        ManufacturerNameColumnHeader = c.Manufacturer.Name,

                        PriceColumnHeader = c.Price,
                    })
                .ToList();

            foreach (var computer in computersReports)
            {
                table.AddCell(computer.ManufacturerNameColumnHeader.ToString());
                table.AddCell(computer.ModelColumnHeader.ToString());
                table.AddCell(computer.PriceColumnHeader.ToString() + " $");
            }
        }
        public void GenerateAutopartsReports(string filePath, string fileName, AutopartsDbContext db)
        {
            fileName = UniqueFileNameGenerator.AddUniqueFilenameSuffix(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);

            var table = this.CreateAutopartsReportsTable();
            this.AddAutopartsReportsTableHeader(table);
            this.AddAutopartsReportsTableColumns(table);
            this.FillAutopartsReportsTableData(table, db);

            document.Open();
            document.Add(table);
            document.Close();
        }
        public void GenerateAutoPartReport(string path)
        {
            var db = new AutopartsDbContext();
            var entries = db.AutoParts.ToList();

            XElement autoParts = new XElement("AutoParts");

            foreach (var entry in entries)
            {
                XElement autoPart = new XElement("AutoPart");
                XElement name = new XElement("Name", entry.Name);
                XElement description = new XElement("Description", entry.Description);
                XElement type = new XElement("Type", entry.Type.Id);
                XElement manufacturer = new XElement("Manufacturer", entry.Manufacturer.Name);
                XAttribute manId = new XAttribute("ID", entry.Manufacturer.Id);
                manufacturer.Add(manId);
                XElement compatibility = new XElement("Compatibility");
                XAttribute compatibilityId = new XAttribute("ID", entry.Compatibility.Id);
                compatibility.Add(compatibilityId);
                XElement model = new XElement("Model", entry.Compatibility.Model.Model);
                XElement brand = new XElement("Model", entry.Compatibility.Brand.Brand);
                XElement price = new XElement("Price", entry.Price);
                XElement quantity = new XElement("Quantity", entry.Quantity);

                autoPart.Add(name);
                autoPart.Add(description);
                autoPart.Add(type);
                autoPart.Add(manufacturer);
                compatibility.Add(brand);
                compatibility.Add(model);
                autoPart.Add(compatibility);
                autoPart.Add(price);
                autoPart.Add(quantity);
                autoParts.Add(autoPart);
            }

            autoParts.Save(path);
        }
        private void FillAutopartsReportsTableData(PdfPTable table, AutopartsDbContext db)
        {
            decimal totalSum = 0;
            var autoPartsReport =
                db.AutoParts.Select(
                    c =>
                    new
                        {
                            ProductName = c.Name,
                            Manufacturer = c.Manufacturer.Name,
                            Price = c.Price,
                            Quantity = c.Quantity,
                            Sum = c.Price * c.Quantity
                        }).ToList();

            foreach (var autopart in autoPartsReport)
            {
                table.AddCell(autopart.ProductName);
                table.AddCell(autopart.Manufacturer);
                table.AddCell(autopart.Price.ToString());
                table.AddCell(autopart.Quantity.ToString());
                table.AddCell(autopart.Sum.ToString());
                totalSum += autopart.Sum;
            }

            var totalCell = new PdfPCell(new Phrase(TotalColumName));
            totalCell.BackgroundColor = BaseColor.LIGHT_GRAY;

            table.AddCell(new PdfPCell { Colspan = 3 });
            table.AddCell(totalCell);
            table.AddCell(totalSum.ToString());
        }