public ActionResult EditOrganization(OrgVM o) { ILocationRepo locorepo = LocationRepoFactory.Create(); IHeroRepo herorepo = HeroRepoFactory.Create(); IOrgRepo orgrepo = OrgRepoFactory.Create(); if (ModelState.IsValid) { o.OrganizationHeroes = new List <Hero>(); var orgToEdit = new Organization { OrganizationID = o.OrganizationID, OganizationAddress = o.OganizationAddress, OrganizationLocation = locorepo.GetLocationById(o.OrganizationLocation.LocationID), OrganizationName = o.OrganizationName, Phone = o.Phone, }; foreach (var HeroID in o.SelectedHeroesID) { orgToEdit.OrganizationHeroes.Add(herorepo.GetHereosByID(HeroID)); } orgrepo.EditOrg(orgToEdit); } return(RedirectToAction("OrganizationList")); }
public ActionResult DeleteLocation(int LocationID) { ILocationRepo locorepo = LocationRepoFactory.Create(); locorepo.DeleteLocation(LocationID); return(RedirectToAction("LocationList")); }
public ActionResult LocationList() { ILocationRepo locorepo = LocationRepoFactory.Create(); var model = locorepo.GetAllLocations(); return(View(model.ToList())); }
public ActionResult EditLocation(int id) { ILocationRepo locorepo = LocationRepoFactory.Create(); var location = locorepo.GetLocationById(id); var model = new LocationVM { LocationID = location.LocationID, LocationName = location.LocationName, LocationAddress = location.LocationAddress, LocationDescription = location.LocationDescription, LatitudeCoordinate = location.LatitudeCoordinate, LongitudeCoordinate = location.LongitudeCoordinate, }; locorepo.EditLocation(location); return(View(model)); }
public ActionResult EditLocation(LocationVM l) { ILocationRepo locorepo = LocationRepoFactory.Create(); if (ModelState.IsValid) { var location = new Location { LocationID = l.LocationID, LocationName = l.LocationName, LocationAddress = l.LocationAddress, LocationDescription = l.LocationDescription, LatitudeCoordinate = l.LatitudeCoordinate, LongitudeCoordinate = l.LongitudeCoordinate, }; locorepo.EditLocation(location); } return(RedirectToAction("LocationList")); }
public ActionResult EditSighting(SightingVM s) { IHeroRepo herorepo = HeroRepoFactory.Create(); ISightingRepo repo = SightingRepoFactory.Create(); ILocationRepo locationrepo = LocationRepoFactory.Create(); if (ModelState.IsValid) { foreach (var hero in s.SightingHeroes) { s.SightingObject.SightingHeroes.Remove(hero); } foreach (var HeroID in s.SightingObject.SelectedHeroesID) { s.SightingObject.SightingHeroes.Add(herorepo.GetHereosByID(HeroID)); } s.SightingObject.SightingLocation = locationrepo.GetLocationById(s.SightingObject.SightingLocation.LocationID); Sighting sighting = new Sighting { Ispublished = true, SightingHeroes = s.SightingObject.SightingHeroes, SightingID = s.SightingObject.SightingID, SightingLocation = s.SightingObject.SightingLocation, SightingDescription = s.SightingObject.SightingDescription, Date = s.SightingObject.Date }; repo.EditSighting(sighting); } else { return(View(s)); } return(RedirectToAction("Index", "Home")); }
protected override void Seed(Superhero.Data.SuperheroDBContext context) { IOrgRepo orgrepo = OrgRepoFactory.Create(); IHeroRepo herorepo = HeroRepoFactory.Create(); ILocationRepo locorepo = LocationRepoFactory.Create(); ISightingRepo sightingrepo = SightingRepoFactory.Create(); var userMgr = new UserManager <IdentityUser>(new UserStore <IdentityUser>(context)); var roleMgr = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); if (!roleMgr.RoleExists("User")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "User"; roleMgr.Create(role); } if (!userMgr.Users.Any(u => u.UserName == "user")) { var user = new IdentityUser() { UserName = "******" }; userMgr.Create(user, "testing"); } var findmanager = userMgr.FindByName("user"); // create the user with the manager class if (!userMgr.IsInRole(findmanager.Id, "user")) { userMgr.AddToRole(findmanager.Id, "user"); } if (!roleMgr.RoleExists("admin")) { roleMgr.Create(new IdentityRole() { Name = "admin" }); } if (!userMgr.Users.Any(u => u.UserName == "admin")) { var user = new IdentityUser() { UserName = "******" }; userMgr.Create(user, "testing"); } var finduser = userMgr.FindByName("admin"); // create the user with the manager class if (!userMgr.IsInRole(finduser.Id, "admin")) { userMgr.AddToRole(finduser.Id, "admin"); } if (!context.Locations.Any(l => l.LocationName == "Minneapolis")) { var firstlocation = new Location { LocationName = "Minneapolis", LocationAddress = "The Twin Cities", LocationDescription = "A lovely city", LatitudeCoordinate = 100, LongitudeCoordinate = 100, }; context.Locations.Add(firstlocation); context.SaveChanges(); } var location = context.Locations.First(l => l.LocationName == "Minneapolis"); if (!context.Organizations.Any(o => o.OrganizationName == "Minneapolis Hero Squad")) { var firstorg = new Organization { OrganizationName = "Minneapolis Hero Squad", OganizationAddress = "S 5th street Minneapolis", OrganizationLocation = location, Phone = "123-456-7899", }; context.Organizations.Add(firstorg); context.SaveChanges(); } var org = context.Organizations.First(l => l.OrganizationName == "Minneapolis Hero Squad"); if (!context.Heroes.Any(h => h.HeroName == "The Flash")) { var firsthero = new Hero { HeroName = "The Flash", Organizations = new Collection <Organization>() { org }, Description = "Wears a red/yellow suit", Superpower = "Runs really fast", }; context.Heroes.Add(firsthero); context.SaveChanges(); } var hero = context.Heroes.First(l => l.HeroName == "The Flash"); if (!context.Sightings.Any(s => s.SightingDescription == "We saw the Flash in Minneapolis")) { var firstsighting = new Sighting { SightingLocation = location, SightingHeroes = new Collection <Hero>() { hero }, Date = DateTime.Today, SightingDescription = "We saw the Flash in Minneapolis", IsDeleted = false, Ispublished = true, }; context.Sightings.Add(firstsighting); } context.SaveChanges(); }