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 }
private void reloadDB() { unloadDB(_cosmoContext); //Helper method to unload items in the context database (ensures fresh dummy data) string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); //bool bFlipTest = environment.Equals("Development"); bool bFlipTest = false; List <Region> regions = loadRegions(); //Helper method to load dummy Regions into Region table if (bFlipTest) { regions.Reverse(); } _cosmoContext.Region.AddRange(regions); //Adds Regions list to context _cosmoContext.SaveChanges(); //Saves changes List <Route> routes = loadRoutes(_cosmoContext.Region.ToList()); //Helper method to load dummy Routes into Route table if (bFlipTest) { routes.Reverse(); } _cosmoContext.Route.AddRange(routes); //Adds routes list to context _cosmoContext.SaveChanges(); //Saves changes loadLocations(_cosmoContext, _cosmoContext.Region.ToList(), bFlipTest); List <Location> locations = _cosmoContext.Location.OrderBy(l => l.locationID).ToList(); List <Subscriber> subscribers = loadSubscribers(locations, _cosmoContext); if (bFlipTest) { subscribers.Reverse(); } //_cosmoContext.Subscriber.AddRange(subscribers); //_cosmoContext.SaveChanges(); //Save changes to DB List <Admin> admins = loadAdmins(); if (bFlipTest) { admins.Reverse(); } _cosmoContext.Admin.AddRange(admins); _cosmoContext.SaveChanges(); //Save changes to DB List <LocationRoute> locationRoutes = loadLocationRoutes(_cosmoContext.Location.ToList(), _cosmoContext.Route.ToList()); //locationRoutes.Reverse(); _cosmoContext.LocationRoute.AddRange(locationRoutes); _cosmoContext.SaveChanges(); //Save changes to DB }
public IActionResult SetSubscriberInactive([FromRoute] int id) { //If we failed the Authorize claims check, the response code will be set to 401 if (this.Response.StatusCode == 401) { return(Unauthorized()); } //check if the object is invalid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //get an existing subscriber matching the email taken from the route Subscriber subscriberInactive = _context.Subscriber.FirstOrDefault(e => e.subscriberID == id); //check if the subscriber id is a valid id if (subscriberInactive == null) { return(NotFound()); } //set the subscriber's inactive status to true subscriberInactive.inactive = true; //update the subscriber in the database using the subscriber "subscriberInactive" object. var isInactive = _context.Subscriber.Update(subscriberInactive) != null ? (IActionResult)Ok(subscriberInactive) : (IActionResult)NotFound(subscriberInactive); //save the changes to the database _context.SaveChanges(); return(isInactive); }
/// <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 static void Reload(CosmoContext context) { context.RemoveRange(context.Location); context.SaveChanges(); Load(context); }
/// <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> /// 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 ActionResult Register(RegisterModel Post) { var Model = new RegisterModel(); var UserEntity = new Users(); if (ModelState.IsValid) { if (UserCheck(Post.UserEmail)) { UserEntity.Name = Post.UserName; UserEntity.Surname = Post.UserSurname; UserEntity.Email = Post.UserEmail; UserEntity.Password = Post.UserPass; Context.Users.Add(UserEntity); Context.SaveChanges(); return(RedirectToAction("Profil", new { UserEmail = Post.UserEmail })); } else { return(View(Model)); } } return(View(Model)); }
public async Task <IActionResult> AssignLocations([FromRoute] int regID, [FromBody] List <Location> locations) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Checks if the regionID is greater than 0 and if it cannot be found if (regID > 0 && _context.Region.Find(regID) == null) { return(BadRequest("Invalid Region ID")); } foreach (Location loc in locations) { if (regID == 0) { loc.regionID = null; } else { if (regID < 0) { return(BadRequest("Invalid Region ID")); } else { loc.regionID = regID; } } } _context.UpdateRange(locations); _context.SaveChanges(); return(Ok(locations)); }
/// <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(); }
public static void Load(CosmoContext context) { context.AddRange(GetDerivedLocations(context)); 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); }
/// <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(); }
/// <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(); }
/// <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(); }