public ActionResult AddOrganization(OrgVM o) { IHeroRepo herorepo = HeroRepoFactory.Create(); IOrgRepo orgrepo = OrgRepoFactory.Create(); if (ModelState.IsValid) { o.OrganizationHeroes = new List <Hero>(); var org = new Organization { SelectedHeroesID = o.SelectedHeroesID, OrganizationID = o.OrganizationID, OrganizationName = o.OrganizationName, OganizationAddress = o.OganizationAddress, OrganizationLocation = o.OrganizationLocation, Phone = o.Phone, }; foreach (var HeroID in o.SelectedHeroesID) { org.OrganizationHeroes.Add(herorepo.GetHereosByID(HeroID)); } orgrepo.AddOrganization(org); } else { return(View(o)); } return(RedirectToAction("OrganizationList")); }
public ActionResult EditHero(HeroVM h) { IHeroRepo herorepo = HeroRepoFactory.Create(); IOrgRepo orgrepo = OrgRepoFactory.Create(); if (ModelState.IsValid) { h.Organizations = new List <Organization>(); var hero = new Hero { HeroID = h.HeroID, HeroName = h.HeroName, Description = h.Description, Sightings = h.Sightings, Superpower = h.Superpower, }; foreach (var OrganizationID in h.SelectedOrganizationsID) { hero.Organizations.Add(orgrepo.GetOrganizationById(OrganizationID)); } herorepo.EditHero(hero); } return(RedirectToAction("HeroList")); }
public ActionResult HeroList() { IHeroRepo herorepo = HeroRepoFactory.Create(); var model = herorepo.GetAllHeroes(); return(View(model.ToList())); }
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 DeleteHero(int HeroID) { IHeroRepo herorepo = HeroRepoFactory.Create(); herorepo.DeleteHero(HeroID); return(RedirectToAction("HeroList")); }
public ActionResult AddSighting(SightingVM s) { IHeroRepo herorepo = HeroRepoFactory.Create(); ISightingRepo repo = SightingRepoFactory.Create(); if (ModelState.IsValid) { repo.AddSighting(s.SightingObject); } else { return(View(s)); } return(RedirectToAction("Index", "Home")); }
public ActionResult EditHero(int id) { IHeroRepo herorepo = HeroRepoFactory.Create(); var hero = herorepo.GetHereosByID(id); var model = new HeroVM { HeroID = hero.HeroID, HeroName = hero.HeroName, Description = hero.Description, Superpower = hero.Superpower, }; foreach (var Org in hero.Organizations) { model.SelectedOrganizationsID.Add(Org.OrganizationID); } return(View(model)); }
public ActionResult EditSighting(int SightingID) { IHeroRepo herorepo = HeroRepoFactory.Create(); ISightingRepo repo = SightingRepoFactory.Create(); Sighting s = repo.GetSightingsById(SightingID); //int locationid = s.SightingLocation.LocationID; var model = new SightingVM() { SightingObject = repo.GetSightingsById(SightingID), Date = s.Date, SightingHeroes = herorepo.GetAllHeroes(), SightingID = s.SightingID }; model.SightingObject.SelectedHeroesID = new List <int>(); foreach (var hero in s.SightingHeroes) { model.SightingObject.SelectedHeroesID.Add(hero.HeroID); } return(View(model)); }
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(); }