public void assignReservation() { using (bowlingEntities db = new bowlingEntities()) { lane lane = (from l in db.lanes join g in db.games on l.Id equals g.Lane_id where g.State != "finished" select l).SingleOrDefault(); db.games.Attach(this); db.Entry(this).State = EntityState.Modified; if (lane != null) this.Lane_id = lane.Id; else this.Lane_id = (from l in db.lanes select l).SingleOrDefault().Id; } }
public void assignToLane() { using (var db = new bowlingEntities()) { lane lane = (from l in db.lanes where l.State == "available" select l).SingleOrDefault(); db.games.Attach(this); db.Entry(this).State = EntityState.Modified; if (lane != null) { this.Lane_id = lane.Id; } else { this.assignReservation(); } db.SaveChanges(); } }
public game createGame() { using (var db = new bowlingEntities()) { db.players.Attach(this); db.Entry(this).State = EntityState.Modified; game game = new game(); game.players.Add(this); try { db.games.Add(game); db.SaveChanges(); } catch (Exception e) { throw new Exception("Error", e); } return game; } }