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 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"); }