public static void ImportToDb(string location)
        {
            var db = new AvalancheTestsDbEntities();

            XDocument document = XDocument.Load(location);

            var places = from place in document.Descendants("Place")
                         select new
                         {
                             Name = place.Attribute("name").Value,
                             Area = place.Attribute("area").Value
                         };

            foreach (var place in places)
            {
                var currentPlace = new Place()
                {
                    PlaceId = new Random().Next(1, 10000),
                    Name = place.Name,
                    Area = DbGeometry.FromText(place.Area)
                };

                db.Places.Add(currentPlace);
            }

            db.SaveChanges();
            db.Dispose();
        }
        public static void CreatePdf()
        {
            var db = new AvalancheTestsDbEntities();

            var groupsTests = db.Tests.Select(t => new
            {
                Name = t.User.Name,
                UserMemberships = t.Organizations.Select(o => o.Name),
                Locations = t.User.Tests.Select(t2 => t2.Place.Name),
                Date = t.Date,
                UsersTestCount = t.User.Tests.Count
            })
                .GroupBy(gr => new { gr.Date.Year, gr.Date.Month })
                .ToList();

            FileStream fileStream = new FileStream(PdfReportFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
            Document doc = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(doc, fileStream);

            doc.Open();

            var table = new PdfPTable(NumberOfColumns);
            table.AddCell("Annual User Tests Report");
            doc.Add(Chunk.NEWLINE);

            foreach (var gr in groupsTests)
            {
                table.AddCell(gr.Key.Year.ToString() + "-" + gr.Key.Month.ToString());
                doc.Add(Chunk.NEWLINE);

                var innerTable = new PdfPTable(4);

                innerTable.AddCell("User Name");
                innerTable.AddCell("User Memberships");
                innerTable.AddCell("Locations");
                innerTable.AddCell("Tests count");

                foreach (var item in gr)
                {
                    innerTable.AddCell(item.Name.ToString());
                    innerTable.AddCell(string.Join(", ", item.UserMemberships) + " ");
                    innerTable.AddCell(string.Join(", ", item.Locations) + " ");
                    innerTable.AddCell(item.UsersTestCount.ToString());
                }

                table.AddCell(innerTable);
            }

            doc.Add(table);
            doc.Close();

            Console.WriteLine("PDF Report created!");
        }
        public static void LastWeek(Place place, DateTime today)
        {
            AvalancheTestsDbEntities db = new AvalancheTestsDbEntities();

            var startDate = today.AddDays(-7);
            List<Test> tests = db.Tests
                .Where(t => t.Place.Name == place.Name)
                .Where(t => (t.Date >= startDate && t.Date <= today))
                .ToList();

            XmlSerializeResult(tests, "weekly-tests-" + place.Name + ".xml");
        }
        public static void LastYear(Place place, DateTime today)
        {
            AvalancheTestsDbEntities db = new AvalancheTestsDbEntities();

            var startDate = today.AddYears(-1);
            var tests = db.Tests
                .Where(t => t.Place.Name == place.Name)
                .Where(t => (t.Date >= startDate && t.Date <= today))
                .GroupBy(gr => new { gr.Date.Year, gr.Date.Month })
                .ToList();

            XmlSerializeResult(tests, "yearly-tests-" + place.Name + ".xml");
        }