public ActionResult Index() { ISightingRepo repo = SightingRepoFactory.Create(); var model = repo.GetNumberOfSightings(10, 0); return(View(model)); }
public IHttpActionResult GetByType(string property, string parameter) { ISightingRepo repo = SightingRepoFactory.Create(); var toReturn = new List <Sighting>(); switch (property) { case "Hero": toReturn = repo.GetSightingsByHero(parameter).ToList(); break; case "Location": toReturn = repo.GetSightingsByLocation(parameter).ToList(); break; case "Sighting": if (parameter[0] == '#') { parameter = parameter.Remove(0, 1); } toReturn = repo.GetSighintsByDate(parameter).ToList(); break; //case "Organization": // toReturn = repo.GetSightingsByOrganization(parameter); // break; } return(Ok(toReturn)); }
public ActionResult PendingSightings() { var repo = SightingRepoFactory.Create(); var model = repo.GetPendingSightings(); return(View(model)); }
public ActionResult DeleteSighting(int SightingID) { ISightingRepo repo = SightingRepoFactory.Create(); repo.DeleteSighting(SightingID); return(RedirectToAction("Index", "Home")); }
public ActionResult PublishSighting(int ID) { var repo = SightingRepoFactory.Create(); Sighting sighting = repo.GetSightingsById(ID); sighting.Ispublished = true; repo.EditSighting(sighting); return(RedirectToAction("PendingSightings")); }
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 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(); }