public Location CreateLocation(Location location, int planId)
        {
            _context.Coordinates.Add(location.Coordinates);

            _context.Locations.Add(location);
            var plan = _context.Plan.Where(l => l.Id == planId).FirstOrDefault();

            _context.PlanLocations.Add(new PlanLocations()
            {
                Plan     = plan,
                Location = location
            });

            _context.SaveChanges();
            return(location);
        }
示例#2
0
        public Plan CreatePlan(Plan plan, Guid userId)
        {
            _context.Plan.Add(plan);
            plan.Created = DateTime.Now;
            plan.Updated = DateTime.Now;

            _context.UserPlans.Add(new UserPlans()
            {
                UserId = userId,
                Plan   = plan,
                Owner  = true
            });

            _context.SaveChanges();
            return(plan);
        }
示例#3
0
        public void InitializeDatabase()
        {
            ClearDB();

            //FeatureCodes, FeatureCategories
            string featureCodeFile = Path.Combine(_options.SeedDataPath, _options.FeatureCodeFile);
            var    features        = ReadFeatureData(featureCodeFile);

            //CountryCodes
            string countryCodeFile          = Path.Combine(_options.SeedDataPath, _options.CountryCodeFile);
            IEnumerable <Country> countries = ReadCountryData(countryCodeFile).ToList();

            //TimeZones
            string timeZoneFile = Path.Combine(_options.SeedDataPath, _options.TimeZoneFile);
            IEnumerable <TimeZone> timezones = ReadTimeZoneData(timeZoneFile, countries).ToList();

            string geoDataFile = Path.Combine(_options.SeedDataPath, _options.GeoDataFile);
            var    geoData     = InitGeoData <GeoData>(geoDataFile, features.codes, countries, timezones).ToList();

            //insert data
            _context.FeatureCodes.AddRange(features.codes);
            _context.FeatureCategories.AddRange(features.categories);
            _context.TimeZones.AddRange(timezones);
            _context.Countries.AddRange(countries);
            _context.GeoData.AddRange(geoData);

            _context.SaveChanges();
        }
 public void Save()
 {
     _context.SaveChanges();
 }