public void GenerateXmlReport(TelecommunicationDbContext db)
        {
            Encoding encoding = Encoding.GetEncoding("windows-1251");
            bool exists = System.IO.Directory.Exists(OutputPath);

            if (!exists)
            {
                System.IO.Directory.CreateDirectory(OutputPath);
            }

            using (XmlTextWriter writer = new XmlTextWriter(OutputPath + OutputFileName, encoding))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                var packages = db.Packages.ToList();

                var summaryFromThеFirstYear = this.GetDataFromDB(packages, YearOfFirstReport);
                var summaryFromTheSecondYear = this.GetDataFromDB(packages, YearOfSecondReport);
                var summaryFromTheThirdYear = this.GetDataFromDB(packages, YearOfThirdReport);
                var summaryFromFourthYear = this.GetDataFromDB(packages, YearOfFourthReport);
                var summaryFromFifthYear = this.GetDataFromDB(packages, YearOfFifthReport);

                var summariesAll = summaryFromThеFirstYear
                    .Concat(summaryFromTheSecondYear)
                    .Concat(summaryFromTheThirdYear)
                    .Concat(summaryFromFourthYear)
                    .Concat(summaryFromFifthYear)
                    .ToList()
                    .GroupBy(s => s.PackName);

                writer.WriteStartDocument();
                writer.WriteStartElement("sales");

                foreach (var summaryPack in summariesAll)
                {
                    writer.WriteStartElement("sale");

                    writer.WriteAttributeString("name", summaryPack.Key);

                    foreach (var summary in summaryPack)
                    {
                        int reportDate = summary.ReportYear;
                        var sum = summary.Sum;
                        CreateSummary(writer, reportDate, sum);
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                Console.WriteLine("XML file is ready!");
            }
        }
        public void GenerateXmlReport(string filePath, TelecommunicationDbContext db)
        {
            var contracts = db.Contracts.ToList();
            var grouped = contracts.GroupBy(x => x.StartDate.Date);

            var element = new XElement("contracts");
            var doc = new XDocument(element);
            foreach (var item in grouped)
            {
                element.Add(new XElement("info-contact", new XElement("Date", item.Key.Date), new XElement("Num-of-contracts", item.Count())));
            }

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

            string fileName = "XMLReport.xml";
            var fullPath = filePath + fileName;
            doc.Save(fullPath);
            Console.WriteLine("XML file is ready!");
        }