public string Get(string name) { bool x = false; MatchQ posted = new MatchQ(); posted.name = name; posted.ready = ready; using (MatchDb db = new MatchDb()) { using (BattleshipDb m = new BattleshipDb()) { while (x == false) { x = true; Random rnd = new Random(); for (int i = 0; i < db.matches.ToList().Count(); i++) { if ((m.Battleships.Where(t => t.gameId == rnd.Next(10000, 1000000)).Count() > 0) && db.matches.Where(t => t.matchId == rnd.Next(10000, 1000000)).Count() > 0) // Check if element exists { x = false; } } } //db.matches.Add(); db.SaveChanges(); return("working f****r"); } } }
//public IEnumerable<MatchQ> Get() public string Get(int id) { using (BattleshipDb db = new BattleshipDb()) { return(db.IsHit.First(t => t.gameId == id)); } }
public string Put(int id, int x, int y) { using (BattleshipDb db = new BattleshipDb()) { if (db.Battleships.Where(t => t.gameId == id).Count() > 0) { db.Battleships.First(t => t.gameId == id).xCoord = x; db.Battleships.First(t => t.gameId == id).yCoord = y; if (db.IsHit.First(t => t.gameId == id).whoseTurn == 0) { db.IsHit.First(t => t.gameId == id).whoseTurn++; } else { db.IsHit.First(t => t.gameId == id).whoseTurn--; } } else { return("broken f****r"); } db.SaveChanges(); return("working f****r"); } }
//public IEnumerable<MatchQ> Get() public Battleship Get(int id) { using (BattleshipDb db = new BattleshipDb()) { return(db.Battleships.First(t => t.gameId == id)); } }
public void Delete(int id) { using (BattleshipDb db = new BattleshipDb()) { if (db.Battleships.Where(t => t.gameId == id).Count() > 0) // Check if element exists { db.Battleships.Remove(db.Battleships.First(t => t.gameId == id)); } if (db.IsHit.Where(t => t.gameId == id).Count() > 0) { db.IsHit.Remove(db.IsHit.First(t => t.gameId == id)); } db.SaveChanges(); } }
public string Put(IsHit someRandomObject) { using (BattleshipDb db = new BattleshipDb()) { var x = db.IsHit.First(t => t.gameId == someRandomObject.gameId); if (db.IsHit.Where(t => t.gameId == someRandomObject.gameId).Count() > 0) { x.hit = someRandomObject.hit; x.whoseTurn = someRandomObject.whoseTurn; x.isWon = someRandomObject.isWon; } else { db.IsHit.Add(someRandomObject); } db.SaveChanges(); return("working f****r"); } }