public ActionResult AddSighting() { var model = new SightingVM(); //model.SightingObject.SelectedHeroesID = new List<int>(); return(View(new SightingVM())); }
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")); }