public IEnumerable <Sighting> GetPendingSightings() { using (var db = new SuperheroDBContext()) { return(db.Sightings.Where(d => d.Ispublished == false).ToList()); } }
public Hero GetHereosByID(int HeroID) { using (var context = new SuperheroDBContext()) { return(context.Heroes.Include("Organizations").Where(h => h.HeroID == HeroID).FirstOrDefault()); } }
public void EditHero(Hero HeroID) { using (var db = new SuperheroDBContext()) { Hero toEdit = db.Heroes.Include("Organizations").SingleOrDefault(h => h.HeroID == HeroID.HeroID); if (toEdit != null) { toEdit.Description = HeroID.Description; toEdit.HeroName = HeroID.HeroName; toEdit.Sightings = HeroID.Sightings; toEdit.Superpower = HeroID.Superpower; var orgsToDelete = new List <Organization>(); foreach (var org in toEdit.Organizations) { orgsToDelete.Add(org); } foreach (var org in orgsToDelete) { toEdit.Organizations.Remove(org); } foreach (var org in HeroID.Organizations) { //db.Organizations.Add(org); toEdit.Organizations.Add(db.Organizations.Single(o => o.OrganizationID == org.OrganizationID)); } db.SaveChanges(); } } }
public IEnumerable <Sighting> GetSightingsByHero(string parameter) { using (var db = new SuperheroDBContext()) { return(db.Sightings.Include("SightingLocation").Include("SightingHeroes").Where(s => s.SightingHeroes.Any(h => h.HeroName == parameter)).ToList()); } }
public Organization GetOrganizationById(int OrganizationID) { using (var db = new SuperheroDBContext()) { return(db.Organizations.Include("OrganizationHeroes").Where(o => o.OrganizationID == OrganizationID).FirstOrDefault()); } }
public List <Sighting> GetSightingsByLocation(string parameter) { using (var db = new SuperheroDBContext()) { return(db.Sightings.Include("SightingLocation").Include("SightingHeroes").Where(s => s.SightingLocation.LocationName == parameter).ToList()); } }
public void EditSighting(Sighting sighting) { sighting.Ispublished = true; using (var db = new SuperheroDBContext()) { Sighting toEdit = db.Sightings.Include("SightingHeroes").SingleOrDefault(s => s.SightingID == sighting.SightingID); if (toEdit != null) { toEdit.SightingDescription = sighting.SightingDescription; toEdit.Date = sighting.Date; toEdit.SightingLocation = db.Locations.Single(l => l.LocationID == sighting.SightingLocation.LocationID); var heroesToDelete = new List <Hero>(); foreach (var hero in toEdit.SightingHeroes) { heroesToDelete.Add(hero); } foreach (var hero in heroesToDelete) { toEdit.SightingHeroes.Remove(hero); } foreach (Hero hero in sighting.SightingHeroes) { toEdit.SightingHeroes.Add(db.Heroes.Single(h => h.HeroID == hero.HeroID)); } db.SaveChanges(); } } }
public Location GetLocationById(int LocationID) { using (SuperheroDBContext context = new SuperheroDBContext()) { return(context.Locations.Where(l => l.LocationID == LocationID).FirstOrDefault()); } }
public IEnumerable <Sighting> GetNumberOfSightings(int number, int set) { using (var db = new SuperheroDBContext()) { var toReturn = db.Sightings.Include("SightingLocation").Include("SightingHeroes").OrderByDescending(s => s.Date).Where(s => s.Ispublished).Skip(number * set).Take(number).ToList(); return(toReturn); } }
public void AddLocation(Location location) { using (var db = new SuperheroDBContext()) { db.Locations.Add(location); db.SaveChanges(); } }
public IEnumerable <Sighting> GetSighintsByDate(string date) { DateTime day = DateTime.Parse(date); using (var db = new SuperheroDBContext()) { return(db.Sightings.Where(s => DbFunctions.TruncateTime(s.Date) == day.Date).ToList()); } }
public IEnumerable <Hero> GetAllHeroes() { using (var db = new SuperheroDBContext()) { var heroes = from h in db.Heroes select h; return(heroes.ToList()); } }
//SuperheroDBContext context = new SuperheroDBContext(); public void AddHero(Hero hero) { using (var db = new SuperheroDBContext()) { //db.Set<Hero>().AddOrUpdate(hero); db.Heroes.Add(hero); db.SaveChanges(); } }
public IEnumerable <Location> GetAllLocations() { using (var db = new SuperheroDBContext()) { var locations = from l in db.Locations select l; return(locations.ToList()); } }
public IEnumerable <Sighting> GetAllSightings() { using (var db = new SuperheroDBContext()) { var sightings = from s in db.Sightings select s; return(sightings.ToList()); } }
public IEnumerable <Organization> GetAllOrganizations() { using (var db = new SuperheroDBContext()) { var orgs = from o in db.Organizations select o; return(orgs.ToList()); } }
public IEnumerable <Hero> GetHereosBySighting(int SightingID) { using (var db = new SuperheroDBContext()) { var hero = db.Sightings.Include("SighintgHeroes").Where(s => s.SightingID == SightingID).FirstOrDefault(); if (hero != null) { return(hero.SightingHeroes); } return(null); } }
public IEnumerable <Hero> GetHereosByOrganization(int OrganizationID) { using (var db = new SuperheroDBContext()) { var org = db.Organizations.Include("OrganizationHeroes").Where(o => o.OrganizationID == OrganizationID).FirstOrDefault(); if (org != null) { return(org.OrganizationHeroes); } return(null); } }
public void DeleteOrganization(int OrganizationID) { using (var db = new SuperheroDBContext()) { Organization toRemove = db.Organizations.SingleOrDefault(o => o.OrganizationID == OrganizationID); if (toRemove != null) { db.Organizations.Remove(toRemove); } db.SaveChanges(); } }
public void DeleteHero(int HeroID) { using (var db = new SuperheroDBContext()) { Hero toRemove = db.Heroes.SingleOrDefault(h => h.HeroID == HeroID); if (toRemove != null) { db.Heroes.Remove(toRemove); } db.SaveChanges(); } }
public void DeleteSighting(int sightingID) { using (var db = new SuperheroDBContext()) { // might be an issue here with capitalization Sighting toRemove = db.Sightings.SingleOrDefault(s => s.SightingID == sightingID); if (toRemove != null) { db.Sightings.Remove(toRemove); } db.SaveChanges(); } }
public void AddOrganization(Organization organization) { using (var db = new SuperheroDBContext()) { organization.OrganizationHeroes.Clear(); organization.OrganizationLocation = db.Locations.FirstOrDefault(l => l.LocationID == organization.OrganizationLocation.LocationID); foreach (var heroID in organization.SelectedHeroesID) { organization.OrganizationHeroes.Add(db.Heroes.Single(h => h.HeroID == heroID)); } db.Organizations.Add(organization); db.SaveChanges(); } }
public void EditLocation(Location LocationID) { using (var db = new SuperheroDBContext()) { Location toEdit = db.Locations.SingleOrDefault(l => l.LocationID == LocationID.LocationID); if (toEdit != null) { toEdit.LatitudeCoordinate = LocationID.LatitudeCoordinate; toEdit.LongitudeCoordinate = LocationID.LongitudeCoordinate; toEdit.LocationAddress = LocationID.LocationAddress; toEdit.LocationDescription = LocationID.LocationDescription; toEdit.LocationName = LocationID.LocationName; db.SaveChanges(); } } }
public void AddSighting(Sighting sighting) { sighting.Ispublished = true; using (var db = new SuperheroDBContext()) { sighting.SightingLocation = db.Locations.FirstOrDefault(l => l.LocationID == sighting.SightingLocation.LocationID); sighting.SightingHeroes = new List <Hero>(); foreach (var HeroID in sighting.SelectedHeroesID) { sighting.SightingHeroes.Add(db.Heroes.First(h => h.HeroID == HeroID)); } db.Sightings.Add(sighting); db.SaveChanges(); } }
//public List<Sighting> GetSightingsByOrganization(Organization sightingorganization) //{ // using (var db = new SuperheroDBContext()) // { // return db.Sightings.Include("SightingLocation").Include("SightingHeroes").Where(s => s.) // } //} //This may need to be just id instead of SightingID public Sighting GetSightingsById(int SightingID) { Sighting toReturn = new Sighting(); using (var db = new SuperheroDBContext()) { var query = from s in db.Sightings.Include("SightingLocation").Include("SightingHeroes") where s.SightingID == SightingID select s; foreach (var sighting in query) { toReturn = sighting; } } return(toReturn); }
public ActionResult ChangePassword(ChangePasswordVM password) { using (var db = new SuperheroDBContext()) { if (password.newPassword == password.newPasswordConfirm) { var userMgr = new UserManager <IdentityUser>(new UserStore <IdentityUser>(db)); userMgr.ChangePassword(User.Identity.GetUserId(), password.oldPassword, password.newPassword); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("newPassword", "Passwords must be the same"); } return(View(password)); } }
public void DeleteLocation(int LocationID) { using (var db = new SuperheroDBContext()) { var orgsToRemove = db.Organizations.Where(o => o.OrganizationLocation.LocationID == LocationID); foreach (var org in orgsToRemove) { db.Organizations.Remove(org); } db.SaveChanges(); Location toRemove = db.Locations.SingleOrDefault(l => l.LocationID == LocationID); if (toRemove != null) { db.Locations.Remove(toRemove); } db.SaveChanges(); } }
public void EditOrg(Organization OrganizationID) { using (var db = new SuperheroDBContext()) { Organization toEdit = db.Organizations.Include("OrganizationHeroes").SingleOrDefault(o => o.OrganizationID == OrganizationID.OrganizationID); if (toEdit != null) { toEdit.OganizationAddress = OrganizationID.OganizationAddress; toEdit.OrganizationLocation = db.Locations.Single(l => l.LocationID == OrganizationID.OrganizationLocation.LocationID); toEdit.OrganizationName = OrganizationID.OrganizationName; toEdit.Phone = OrganizationID.Phone; toEdit.OrganizationHeroes.Clear(); db.SaveChanges(); foreach (Hero hero in OrganizationID.OrganizationHeroes) { //db.Heroes.Attach(hero); toEdit.OrganizationHeroes.Add(db.Heroes.Single(h => h.HeroID == hero.HeroID)); } db.SaveChanges(); } } }