//methods------------------------------------------------------ public Team addteam(Team newTeam, int gameId) { int startBonus = 30; newTeam.Punten = startBonus; Game game = context.Games.Where(d => d.GameCode == gameId).Include(r => r.Teams).Single <Game>(); if (game != null) { if (game.Teams == null) { //Dit is het eerste team game.Teams = new List <Team>(new Team[] { newTeam }); context.SaveChanges(); return(newTeam); } else { game.Teams.Add(newTeam); context.SaveChanges(); return(newTeam); } } else { return(null); } }
public bool addLoc(DoelLocatie newDoel) { //DoelLocatie doel = context.DoelLocaties.Where(r=> r==newDoel).Include(r=>r.locatie).Single<DoelLocatie>(); if (newDoel != null) { context.DoelLocaties.Add(newDoel); context.SaveChanges(); return(true); } else { return(false); } }
public static void Initialize(CityCheckContext context) { //create the db is not exist yet context.Database.EnsureCreated(); //Default wat doellocaties al in de db steken //zijn er al doellocaties? if (!context.DoelLocaties.Any()) { //er zijn nog geen doellocaties //We steken er standaard een aantal belangrijke in. var doel = new DoelLocatie(); var loc = new Locatie(); //Antwoorden instellen var ant1 = new Antwoord(); ant1.CorrectBool = false; ant1.Antwoordzin = "Groenplaats"; var ant2 = new Antwoord(); ant2.CorrectBool = true; ant2.Antwoordzin = "Eilandje"; var ant3 = new Antwoord(); ant3.CorrectBool = false; ant3.Antwoordzin = "Rooseveld"; //Vraag toevoegen var ques = new Vraag(); ques.VraagZin = "Waar zijn we?"; ques.Antwoorden = new System.Collections.Generic.List <Antwoord>(); ques.Antwoorden.Add(ant1); ques.Antwoorden.Add(ant2); ques.Antwoorden.Add(ant3); //mas doel.Titel = "Mas"; loc.Lat = 51.2289238; loc.Long = 4.4026316; doel.locatie = loc; doel.Vragen = new System.Collections.Generic.List <Vraag>(); doel.Vragen.Add(ques); context.DoelLocaties.Add(doel); context.SaveChanges(); //centraal station doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Centraal Station"; loc.Lat = 51.2183305; loc.Long = 4.4204524; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //kathedraal doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "OlvKathedraal"; loc.Lat = 51.2202678; loc.Long = 4.399327; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //het steen doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Steen"; loc.Lat = 51.2227238; loc.Long = 4.395175; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //Hendrik Conscienceplein doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Hendrik Conscienceplein"; loc.Lat = 51.2211204; loc.Long = 4.4021283; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //Groenplaats doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Groenplaats"; loc.Lat = 51.2189511; loc.Long = 4.3989123; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //Boerentoren doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Boerentoren"; loc.Lat = 51.2185463; loc.Long = 4.4042931; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //demo stuff doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Demo1"; loc.Lat = 51.2202678; loc.Long = 4.399327; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Demo2"; loc.Lat = 51.2202678; loc.Long = 4.399327; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); doel = new DoelLocatie(); loc = new Locatie(); doel.Titel = "Demo3"; loc.Lat = 51.2202678; loc.Long = 4.399327; doel.locatie = loc; context.DoelLocaties.Add(doel); context.SaveChanges(); //if } }
public Game CreateGame(Game newGame) { IQueryable <Game> query = context.Games; //random game code genereren string gameCodeStr = ""; do { int tempGameCode; gameCodeStr = ""; Random rnd = new Random(); for (int i = 0; i < 4; i++) { tempGameCode = rnd.Next(1, 9); gameCodeStr += tempGameCode.ToString(); } //controleren of er al een game is met deze code } while (query.Where(d => d.GameCode == Int32.Parse(gameCodeStr)) == null); newGame.GameCode = Int32.Parse(gameCodeStr); //random game code einde //random doellocaties toevoegen aan de game List <DoelLocatie> doelen = new List <DoelLocatie>(); List <DoelLocatie> alleLocs = context.DoelLocaties.Include(r => r.locatie).ToList <DoelLocatie>(); int totaalLocs = alleLocs.Count(); int aantalTeZoekenLocs = newGame.TijdsDuur * 6; //6x10minuten per tijdsduur uren. Random rndLocInd = new Random(); for (int i = 0; i < aantalTeZoekenLocs; i++) { int newIndex1 = 0; int newIndex2 = 0; int newIndex3 = 0; do { //Steeds 3 verschillende locaties newIndex1 = rndLocInd.Next(0, totaalLocs); newIndex2 = rndLocInd.Next(0, totaalLocs); newIndex3 = rndLocInd.Next(0, totaalLocs); } while (newIndex1 == newIndex2 || newIndex1 == newIndex3 || newIndex2 == newIndex3 || newIndex3 == newIndex1); doelen.Add(alleLocs[newIndex1]); doelen.Add(alleLocs[newIndex2]); doelen.Add(alleLocs[newIndex3]); } //Unieke gegenereerde lijst van doellocaties toevoegen aan de gameDoelen van de huidige game. newGame.GameDoelen = new List <GameDoelen>(); foreach (DoelLocatie doelL in doelen) { GameDoelen tempDoel = new GameDoelen { Doel = doelL, Claimed = false }; newGame.GameDoelen.Add(tempDoel); } //doellocaties toevoegen aan de game context.Games.Add(newGame); context.SaveChanges(); return(newGame); }