public Vraag getALocQuest(int id)
        {
            //id is de doellocatie id

            //vragen ophalen
            DoelLocatie  doel   = context.DoelLocaties.Include(r => r.Vragen).ThenInclude(y => y.Antwoorden).Where(r => r.Id == id).Single <DoelLocatie>();
            List <Vraag> vragen = doel.Vragen;
            //aantal vragen
            int vragenAmount = vragen.Count;


            //random vraag positie bepalen
            Random rand           = new Random();
            int    randomVraagPos = rand.Next(0, vragenAmount);
            Vraag  vraag          = vragen[randomVraagPos];

            if (vraag != null)
            {
                return(vraag);
            }
            else
            {
                return(null);
            }
        }
        public bool addQuest(Vraag newVraag, int id)
        {
            //id is de id van de doellocatie

            DoelLocatie doel = context.DoelLocaties.Include(r => r.Vragen).ThenInclude(y => y.Antwoorden).Where(r => r.Id == id).Single <DoelLocatie>();

            if (doel != null && newVraag != null)
            {
                if (doel.Vragen != null)
                {
                    //nieuwe vraag opslaan
                    doel.Vragen.Add(newVraag);
                }
                else
                {
                    doel.Vragen = new List <Vraag>();
                    doel.Vragen.Add(newVraag);
                }
                context.SaveChanges();
                return(true);
            }
            else
            {
                //geen vraag
                return(false);
            }
        }
        public bool delQuest(int id, int vid)
        {
            //id is de id van de doellocatie


            DoelLocatie     doel       = null;
            Vraag           vraag      = null;
            List <Antwoord> antwoorden = null;


            try
            {
                doel       = context.DoelLocaties.Include(vr => vr.Vragen).ThenInclude(antw => antw.Antwoorden).Where(whr => whr.Id == id).Single <DoelLocatie>();
                vraag      = doel.Vragen.Where(r => r.Id == vid).Single <Vraag>();
                antwoorden = vraag.Antwoorden;
            }
            catch
            {
                Console.WriteLine("Geen Content");
            }

            if (vraag != null)
            {
                context.Antwoorden.RemoveRange(antwoorden);
                context.Vragen.Remove(vraag);
                context.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public IActionResult editLoc([FromBody] DoelLocatie newDoel, int id)
        {
            var doelEdited = doelMethods.editLoc(newDoel, id);

            if (!doelEdited)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(newDoel));
            }
        }
Beispiel #5
0
        public IActionResult addLoc([FromBody] DoelLocatie newDoel)
        {
            var doelAdded = doelMethods.addLoc(newDoel);

            if (!doelAdded)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(newDoel));
            }
        }
        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 bool delLoc(int id)
        {
            DoelLocatie doelToDeleted = context.DoelLocaties.Find(id);

            if (doelToDeleted != null)
            {
                //Delete location
                context.DoelLocaties.Remove(doelToDeleted);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public List <Vraag> getAllLocsQuest(int id)
        {
            //alle vragen ophalen op 1 locatie inclusief antwoorden
            DoelLocatie  doelenQuery = context.DoelLocaties.Include(r => r.Vragen).ThenInclude(y => y.Antwoorden).Where(r => r.Id == id).Single <DoelLocatie>();
            List <Vraag> vragenQuery = doelenQuery.Vragen.ToList <Vraag>();


            if (vragenQuery != null)
            {
                return(vragenQuery);
            }
            else
            {
                return(null);
            }
        }
        public bool editLoc(DoelLocatie newDoel, int id)
        {
            if (newDoel != null)
            {
                //doellocatie zoeken
                DoelLocatie huidigeLoc = context.DoelLocaties.Include(r => r.locatie).Include(vr => vr.Vragen).ThenInclude(y => y.Antwoorden).Where(r => r.Id == id).Single <DoelLocatie>();
                //Locatie titel en locatie aanpassen
                huidigeLoc.Titel = newDoel.Titel;
                //context.Locaties.Remove(huidigeLoc.locatie);
                huidigeLoc.locatie.Lat  = newDoel.locatie.Lat;
                huidigeLoc.locatie.Long = newDoel.locatie.Long;

                //edits opslaan
                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 createDemoGame(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

            //demo doellocaties toevoegen aan de game

            List <DoelLocatie> doelen = new List <DoelLocatie>();

            List <DoelLocatie> alleLocs = context.DoelLocaties.Include(r => r.locatie).ToList <DoelLocatie>();

            //De 3 demo locaties ophalen
            DoelLocatie doel1 = alleLocs.Where(doel => doel.Titel == "Demo1").SingleOrDefault <DoelLocatie>();
            DoelLocatie doel2 = alleLocs.Where(doel => doel.Titel == "Demo2").SingleOrDefault <DoelLocatie>();
            DoelLocatie doel3 = alleLocs.Where(doel => doel.Titel == "Demo3").SingleOrDefault <DoelLocatie>();

            //Lijst van doelen opstellen voor de volledige game length
            int gameLength = newGame.TijdsDuur;

            //Per uur 6x 3 doellacties toevoegen
            for (int j = 0; j < 6 * gameLength; j++)
            {
                doelen.Add(doel1);
                doelen.Add(doel2);
                doelen.Add(doel3);
            }

            newGame.GameDoelen = new List <GameDoelen>();
            context.Games.Add(newGame);
            context.SaveChanges();

            //lijst van doellocaties toevoegen aan de gameDoelen van de huidige game.
            foreach (DoelLocatie doelL in doelen)
            {
                GameDoelen tempDoel = new GameDoelen {
                    Doel = doelL, Claimed = false
                };
                newGame.GameDoelen.Add(tempDoel);
                context.SaveChanges();
            }


            return(newGame);
        }