public bool UpdateGame(GameVM vm) { using (PlayContext context = new PlayContext()) { try { Game game = context.Games.Single(x => x.ID == vm.Game.ID); Location loc = new Entities.Location(); game.Name = vm.Game.Name; game.Type = vm.Game.Type; game.Description = vm.Game.Description; game.Start = vm.Game.Start; game.End = vm.Game.End; game.Modified = DateTime.Now; loc.Name = vm.Game.Location.Name; loc.Coordinates = CreatePoint(vm.Latitude, vm.Longitude); game.Location = loc; context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public List <Game> GetAll() { using (PlayContext context = new PlayContext()) { List <Game> list = context.Games .Include("Location") .Include("Attendance") .ToList(); return(list); } }
public Game GetByID(int id) { using (PlayContext context = new PlayContext()) { var game = context.Games .Include("Location") .Include("Attendance") .FirstOrDefault(x => x.ID == id); return(game); } }
public bool DeleteGame(int id) { using (PlayContext context = new PlayContext()) { try { Game game = context.Games.Single(x => x.ID == id); context.Games.Remove(game); context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }