public static void Reload(CosmoContext context) { context.RemoveRange(context.Location); context.SaveChanges(); Load(context); }
private void HighlyPopulateRoute(CosmoContext context, Route r) { Region reg = context.Region.Where(rg => rg.regionName.Equals("A Past Region")).FirstOrDefault(); //Gets Regions from context. Needed to assign required regionID and region properties List <Location> l = context.Location.ToList <Location>(); List <Subscriber> s = context.Subscriber.ToList <Subscriber>(); for (int i = 0; i <= 100; i++) { Location loc = new Location { regionID = reg.regionID, address = i + " Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", }; Subscriber sub = new Subscriber() { email = "Z" + i + "@mushroomkingdom.com", firstName = "Test" + i, phoneNumber = "1234567890", location = loc, billingLocation = loc }; context.Subscriber.Add(sub); context.Location.Add(loc); } }
/// <summary> /// This method will remove all Routes from the TestCosmoDB and then add new routes back into the TestCosmoDB /// Will need to update later to account for additional fixtures /// </summary> /// <param name="context"></param> public static void Reload(CosmoContext context) { context.RemoveRange(context.Subscriber); //Tracks the routes that are removed. context.SaveChanges(); Load(context); //calls the Load method to load new routes into the TestCosmoDB }
public async void Load(CosmoContext context) { await unloadDB(context); List <Region> regionList = getRegions(); context.Region.AddRange(regionList); context.SaveChanges(); regionList = regionList.OrderBy(reg => reg.regionID).ToList(); getLocations(context, regionList); List <Location> locationList = context.Location.OrderBy(loc => loc.locationID).ToList(); List <Route> routeList = getRoutes(regionList); context.Route.AddRange(routeList); context.SaveChanges(); List <Subscriber> subscriberList = getSubscribers(locationList, context); //context.Subscriber.AddRange(subscriberList); //context.SaveChanges(); List <Admin> adminList = getAdmins(); context.Admin.AddRange(adminList); context.SaveChanges(); //Save changes to DB }
static void Main(string[] args) { CosmoContext context = new CosmoContext(); _unitOfWork = new UnitOfWork(context); RegisterServices(); ShowMenu(); Console.ReadLine(); }
private static Task <int> unloadDB(CosmoContext context) { context.RemoveRange(context.Subscriber); //Remove contents of Subscriber table from context context.RemoveRange(context.Location); //Remove contents of Location table from context context.RemoveRange(context.Route); //Remove contents of Route table from context context.RemoveRange(context.Region); //Remove contents of Region table from context context.RemoveRange(context.Admin); return(context.SaveChangesAsync()); //Save changes }
public void LoadLogansLoopLocations(CosmoContext context, List <Region> regionList) { unloadDB(context); List <Location> locations = new List <Location>(); List <Subscriber> subscribers = new List <Subscriber>(); locations.Add(new Location { address = "123 street", province = "Saskatchewan", postalCode = "A1A1A1", optoutLocationRouteList = new List <LocationRoute>(), regionID = regionList[0].regionID }); subscribers.Add(new Subscriber { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Cosmo", location = locations[0] }); locations.Add(new Location { address = "456 street", province = "Saskatchewan", postalCode = "A2A2A2", optoutLocationRouteList = new List <LocationRoute>(), regionID = regionList[0].regionID }); subscribers.Add(new Subscriber { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Nathan", location = locations[1] }); locations.Add(new Location { address = "123 street", province = "Saskatchewan", postalCode = "A2A2A2", optoutLocationRouteList = new List <LocationRoute>(), regionID = regionList[0].regionID }); subscribers.Add(new Subscriber { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Cosmo", location = locations[2] }); context.AddRange(locations); context.AddRange(subscribers); }
/// <summary> /// Helper Method to remove contents of the Context /// </summary> /// <param name="context"></param> private void unloadDB(CosmoContext context) { context.Subscriber.RemoveRange(context.Subscriber); context.Location.RemoveRange(context.Location); context.Region.RemoveRange(context.Region); //Remove contents of Region table from context context.Route.RemoveRange(context.Route); //Remove contents of Route table from context context.Admin.RemoveRange(context.Admin); context.LocationRoute.RemoveRange(context.LocationRoute); context.SaveChanges(); //Save changes }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, CosmoContext context) { //Checks if the environment the webApp is hosted in is a development environment if (env.IsDevelopment()) { dateCalculation = new DateCalculation(); app.UseDeveloperExceptionPage(); //Provides the Developer Exception Page. Page gives information on errors thrown, requests, queries, and others context.Database.EnsureDeleted(); context.Database.EnsureCreated(); //Checks that the context's database is created. Returns true if it is, false if not unloadDB(context); //Helper method to unload items in the context database (ensures fresh dummy data) List <Region> regions = loadRegions(); //Helper method to load dummy Regions into Region table context.AddRange(regions); //Adds Regions list to context context.SaveChanges(); //Saves changes //List<Location> locations = loadLocations(regions); //Create locations with regions passed in //context.Location.AddRange(locations); //context.SaveChanges(); loadLocations(context, regions); List <Location> locations = context.Location.ToList(); List <Subscriber> subscribers = loadSubscribers(locations); //Create the subscribers with the locations passed in context.Subscriber.AddRange(subscribers); context.SaveChanges(); //Save changes to DB List <Route> routes = loadRoutes(regions); //Helper method to load dummy Routes into Route table context.AddRange(routes); //Adds routes list to context context.SaveChanges(); //Saves changes List <Admin> admins = loadAdmins(); //Create the admins context.Admin.AddRange(admins); context.SaveChanges(); //Save changes to DB List <LocationRoute> locationRoutes = loadLocationRoutes(locations, routes); //Create the locationRoutes with the locations and routes passed in context.LocationRoute.AddRange(locationRoutes); context.SaveChanges(); //Save changes to DB //Highly populate route 'S90 A Past Route' HighlyPopulateRoute(context, routes[0]); //Added for Enable CORS Tutorial https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1 //Tells the application to run the given policy name app.UseCors(MyAllowSpecificOrigins); context.SaveChanges(); } app.UseAuthentication(); app.UseMvc(); //Adds MVC to the .Net Core REquest Execution Pipeline }
/// <summary> /// This method will create a new list of routes for testing. Routes are created without RouteIDs /// so they can be added into the test DB without issues /// </summary> /// <returns></returns> public static List <Route> GetRouteFixtures(CosmoContext context) { //DateTime date = DateTime.Today; //Gets todays date. Later used to ensure dates are in the future List <Region> regions = context.Region.ToList <Region>(); //Gets Regions from context. Needed to assign required regionID and region properties return(new List <Route>() //Creating route objects. Dates are generated based on region's first pickup date. Set it up to generate the next three upcoming sets of route dates { //Week 1 Routes new Route() { routeName = "Logan's Loop", regionID = regions[0].regionID, region = regions[0], completed = true }, new Route() { routeName = "Nathan's Circuit", regionID = regions[1].regionID, region = regions[1], completed = true }, new Route() { routeName = "Original Name 3", regionID = regions[2].regionID, region = regions[2], completed = true }, //Week 2 Routes new Route() { routeName = "Logan's Loop", regionID = regions[0].regionID, region = regions[0], completed = true }, new Route() { routeName = "Nathan's Circuit", regionID = regions[1].regionID, region = regions[1], completed = true }, new Route() { routeName = "Original Name 3", regionID = regions[2].regionID, region = regions[2], completed = true }, //Week 3 Routes new Route() { routeName = "Logan's Loop", regionID = regions[0].regionID, region = regions[0], completed = false }, new Route() { routeName = "Nathan's Circuit", regionID = regions[1].regionID, region = regions[1], completed = false }, new Route() { routeName = "Original Name 3", regionID = regions[2].regionID, region = regions[2], completed = false }, }); }
/// <summary> /// Calls GetHardCodedRoutes and adds the newly created routes into the Route table of TestCosmoDB /// This method will need to be modified once additional data fixtures are added /// </summary> /// <param name="context"></param> public static void Load(CosmoContext context) { LocationFixture.Reload(context); List <Location> locations = context.Location.ToList <Location>(); List <Subscriber> subscribers = GetDerivedSubscribers(); int count = 0; foreach (Location l in locations) { subscribers[count].location = l; subscribers[count].billingLocation = l; count++; } context.AddRange(subscribers); context.SaveChanges(); }
public WebAppController(CosmoContext context) { _cosmoContext = context; dateCalculation = new DateCalculation(); }
/// <summary> /// This method will remove the existing routes from the TestCosmoDB and commits the changes /// Will need to update later to account for additional fixtures /// </summary> /// <param name="context"></param> public static void Unload(CosmoContext context) { context.RemoveRange(context.Subscriber); context.SaveChanges(); }
public PlanetRepository(CosmoContext context) : base(context) { }
public RegionsController(CosmoContext context) { _context = context; dateCalculation = new DateCalculation(); }
public static List <Location> GetDerivedLocations(CosmoContext context) { List <Location> locations = new List <Location>(); for (int i = 0; i < 5; i++) { string sCity = ""; switch (i) { case (0): sCity = "Saskatoon"; break; case (1): sCity = "Regina"; break; case (2): sCity = "Prince Albert"; break; case (3): sCity = "Swift Current"; break; case (4): sCity = "North Battleford"; break; } locations.Add(new Location() { city = sCity, locationType = "Pickup", postalCode = "A1A1A1", province = "Saskatchewan", address = "123 Street" }); } //S79 Locations Region s79Reg = context.Region.AsNoTracking().Where(reg => reg.regionName == "The New World").Single(); string[] strAssignedLocs = { "Astera", "Ancient Forest", "Wildspire Wastes", "Coral Highlands", "Rotten Vale", "Elder's Recess" }; string[] strAssignedUnits = { "1A", "2B", "3C", "11A", "11B", "11C" }; for (int i = 0; i < strAssignedLocs.Length; i++) { locations.Add(new Location() { city = strAssignedLocs[i], region = s79Reg, regionID = s79Reg.regionID, address = "123 Illusory Path", unit = strAssignedUnits[i], postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } string[] strUnassignedLocs = { "Seliana", "Hoarfrost Reach", "Guiding Lands", "Origin Isle" }; string[] strUnassignedUnits = { "123", "456", "789", "001" }; for (int i = 0; i < strUnassignedLocs.Length; i++) { locations.Add(new Location() { city = strUnassignedLocs[i], address = "123 Hidden Way", unit = strUnassignedUnits[i], postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } return(locations); }
public SubscribersController(CosmoContext context) { _context = context; }
public RoutesController(CosmoContext context) { _context = context; }
/// <summary> /// Calls GetRoutesFixture and adds the newly created routes into the Route table of TestCosmoDB /// This method will need to be modified once additional data fixtures are added /// </summary> /// <param name="context"></param> public static void Load(CosmoContext context) { context.AddRange(GetRouteFixtures(context)); context.SaveChanges(); }
private void loadLocations(CosmoContext context, List <Region> regions, bool bFlip) { List <Location> locations = new List <Location>() { //Location for the first hard coded subscribers //Do not change new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", region = regions[3] }, //Location for the second hard coded subscribers //Do not change new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", region = regions[4] }, //Location for the third hard coded subscribers //Do not change new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp" //, //region = regions[7] }, //Using this for testing due to it having a proper route that is active and not completed new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", region = regions[0] }, //Location for the second hard coded subscribers new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", region = regions[4] }, //Location for the third hard coded subscribers new Location { address = "123 Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", region = regions[5] } }; //if(bFlip) //{ // locations.Reverse(); //} context.AddRange(locations); context.SaveChanges(); //S79 Locations Region s79Reg = regions.Where(reg => reg.regionName == "The New World").Single(); List <Location> S79LocAssigned = new List <Location>(); List <Location> S79LocUnassigned = new List <Location>(); string[] strAssignedLocs = { "Astera", "Ancient Forest", "Wildspire Wastes", "Coral Highlands", "Rotten Vale", "Elder's Recess", "Great Ravine", "Everstream", "Confluence of Fates", "Research Base" }; string[] strAssignedUnits = { "1A", "2B", "3C", "11A", "11B", "11C" }; for (int i = 0; i < strAssignedLocs.Length; i++) { if (i < 6) { S79LocAssigned.Add(new Location() { city = "World", region = s79Reg, regionID = s79Reg.regionID, address = "123 " + strAssignedLocs[i] + " Path", unit = strAssignedUnits[i], postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } else { S79LocAssigned.Add(new Location() { city = "World", region = s79Reg, regionID = s79Reg.regionID, address = "123 " + strAssignedLocs[i] + " Path", postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } } //if(bFlip) //{ // S79LocAssigned.Reverse(); //} context.AddRange(S79LocAssigned); context.SaveChanges(); string[] strUnassignedLocs = { "Seliana", "Hoarfrost Reach", "Guiding Lands", "Origin Isle", "Canteen", "Smithy", "The Gathering Hub", "Living Quarters", "Private Quarters", "Private Suite" }; string[] strUnassignedUnits = { "123", "456", "789", "001" }; for (int i = 0; i < strUnassignedLocs.Length; i++) { if (i < 4) { S79LocUnassigned.Add(new Location() { city = "Iceborne", address = "123 " + strUnassignedLocs[i] + " Way", unit = strUnassignedUnits[i], postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } else { S79LocUnassigned.Add(new Location() { city = "Iceborne", address = "123 " + strUnassignedLocs[i] + " Way", postalCode = "A1A 1A1", province = "SK", locationType = "Pickup", }); } } //if(bFlip) //{ // S79LocUnassigned.Reverse(); //} context.AddRange(S79LocUnassigned); context.SaveChanges(); }
private List <Subscriber> loadSubscribers(List <Location> locations, CosmoContext context) { //Create a list of hardcoded subscribers so we can sign in on the front end List <Subscriber> subscribers = new List <Subscriber>() { new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Cosmo", location = locations[0], billingLocation = locations[0] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Nathan", location = locations[1], billingLocation = locations[1] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "NathanNoRegion", location = locations[2], billingLocation = locations[2] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Cosmo", location = locations[3], billingLocation = locations[3] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Money", location = locations[4], billingLocation = locations[4] }, //3 more new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Nathan", location = locations[5], billingLocation = locations[5] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", firstName = "Rob", lastName = "Miller", location = locations[0], billingLocation = locations[0] }, new Subscriber() { email = "*****@*****.**", phoneNumber = "1234567890", location = locations[1], billingLocation = locations[1] }, new Subscriber() { email = "*****@*****.**", firstName = "Aaron", lastName = "Atkinson", phoneNumber = "1234567890", location = locations[2], billingLocation = locations[2] }, new Subscriber() { email = "*****@*****.**", firstName = "Jessie", lastName = "Smith", phoneNumber = "1234567890", location = locations[3], billingLocation = locations[3] }, new Subscriber() { email = "*****@*****.**", firstName = "Mario", phoneNumber = "1234567890", location = locations[4], billingLocation = locations[4] }, new Subscriber() { email = "*****@*****.**", firstName = "Luigi", phoneNumber = "1234567890", location = locations[5], billingLocation = locations[5] }, new Subscriber() { email = "*****@*****.**", firstName = "Peach", phoneNumber = "1234567890", location = locations[0], billingLocation = locations[0] } }; context.Subscriber.AddRange(subscribers); context.SaveChanges(); List <Subscriber> hunters = new List <Subscriber>(); for (int i = 0; i < locations.Count - 6; i++) { Subscriber newSub = new Subscriber { email = "hunter" + (i + 1) + "@thenewworld.com", firstName = "Hunter" + (i + 1), phoneNumber = "1111111111", locationID = locations[6 + i].locationID, billingLocationID = locations[6 + i].locationID }; hunters.Add(newSub); } context.Subscriber.AddRange(hunters); context.SaveChanges(); Route r = context.Route.Where(e => e.routeName.Equals("S90 A Past Route")).FirstOrDefault(); List <Location> l = context.Location.ToList <Location>(); for (int i = 0; i <= 100; i++) { Location loc = new Location { regionID = r.regionID, address = i + " Street", city = "Saskatoon", postalCode = "A1A1A1", province = "SK", locationType = "PickUp", }; Subscriber sub = new Subscriber() { email = "Z" + i + "@mushroomkingdom.com", firstName = "Test" + i, phoneNumber = "1234567890", location = loc, billingLocation = loc }; context.Subscriber.Add(sub); context.Location.Add(loc); } context.SaveChanges(); return(subscribers); }
public LocationRoutesController(CosmoContext context) { _context = context; }
public static void Load(CosmoContext context) { context.AddRange(GetDerivedLocations(context)); context.SaveChanges(); }
/// <summary> /// Removes any admins currently in the context /// </summary> /// <param name="context"></param> public static void Unload(CosmoContext context) { context.RemoveRange(context.Admin); context.SaveChanges(); }
public StarRepository(CosmoContext context) : base(context) { }
public Repository(CosmoContext context) { this._context = context; this._entities = context.Set <TEntity>(); }
public AdminsController(CosmoContext context) { _context = context; }
/// <summary> /// Calls GetAdminFixture to get a list of preset regions to load to context /// </summary> /// <param name="context"></param> public static void Load(CosmoContext context) { context.AddRange(GetAdminFixture()); context.SaveChanges(); }