public async Task <ActionResult <PollGebruiker> > PostPollGebruiker(PollGebruiker pollGebruiker)
        {
            _context.PollGebruikers.Add(pollGebruiker);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPollGebruiker", new { id = pollGebruiker.PollGebruikerId }, pollGebruiker));
        }
예제 #2
0
        public async Task <ActionResult <Poll> > PostPoll([FromBody] PollDto pollDto)
        {
            List <Antwoord>      antwoorden     = new List <Antwoord>();
            List <PollGebruiker> pollgebruikers = new List <PollGebruiker>();
            Poll poll = new Poll {
                Naam = pollDto.Naam
            };

            _context.Polls.Add(poll);
            _context.SaveChanges();
            poll = _context.Polls.Last();

            foreach (var a in pollDto.Antwoorden)
            {
                Antwoord antwoord = new Antwoord {
                    AntwoordP = a.AntwoordP, PollID = poll.PollID
                };
                antwoorden.Add(antwoord);
            }

            foreach (var v in pollDto.Vrienden)
            {
                PollGebruiker pollGebruiker = new PollGebruiker {
                    GebruikerID = v.GebruikerID, PollID = poll.PollID, gemaaktDoor = pollDto.gemaaktDoor
                };
                pollgebruikers.Add(pollGebruiker);
            }

            _context.Antwoorden.AddRange(antwoorden);
            _context.PollGebruikers.AddRange(pollgebruikers);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> PutPollGebruiker(long id, PollGebruiker pollGebruiker)
        {
            if (id != pollGebruiker.PollGebruikerId)
            {
                return(BadRequest());
            }

            _context.Entry(pollGebruiker).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PollGebruikerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostPollGebruiker([FromBody] PollGebruiker pollGebruiker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PollGebruikers.Add(pollGebruiker);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPollGebruiker", new { id = pollGebruiker.PollGebruikerID }, pollGebruiker));
        }
        public async Task <ActionResult <PollGebruiker_dto> > PostPollGebruiker(PollGebruiker_dto pollGebruiker)
        {
            var pg1 = new PollGebruiker()
            {
                UserID = pollGebruiker.UserID, PollID = pollGebruiker.PollID, isAdmin = pollGebruiker.isAdmin
            };

            _context.PollGebruiker.Add(pg1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPollGebruiker", new { id = pg1.PollGebruikerID }, pg1));
        }
예제 #6
0
        public async Task <ActionResult <PollGebruiker> > DeletePG(long id, long id2)
        {
            PollGebruiker pollGebruiker = new PollGebruiker();

            pollGebruiker = _context.PollGebruikers.Where(p => p.PollID == id).Where(p => p.GebruikerID == id2).FirstOrDefault();

            if (pollGebruiker == null)
            {
                return(NotFound());
            }

            _context.PollGebruikers.Remove(pollGebruiker);
            await _context.SaveChangesAsync();

            return(pollGebruiker);
        }
예제 #7
0
        public async Task <ActionResult <PollGebruiker> > PostPollGebruiker([FromBody] PollGebruikerDto pollGebruikerDto)
        {
            List <PollGebruiker> pollgebruikers = new List <PollGebruiker>();

            foreach (var v in pollGebruikerDto.Vrienden)
            {
                PollGebruiker pollGebruiker = new PollGebruiker {
                    GebruikerID = v.GebruikerID, PollID = pollGebruikerDto.PollID, gemaaktDoor = pollGebruikerDto.gemaaktDoor
                };
                pollgebruikers.Add(pollGebruiker);
            }

            _context.PollGebruikers.AddRange(pollgebruikers);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #8
0
        public async Task <ActionResult <PollGebruiker> > AddPollGebruikers(long id, List <Gebruiker> Gebruikers)
        {
            PollGebruiker pgs = new PollGebruiker();

            foreach (var gebruiker in Gebruikers)
            {
                PollGebruiker pg = new PollGebruiker();
                pg.GebruikerID = gebruiker.GebruikerID;
                pg.PollID      = id;
                _context.PollGebruikers.Add(pg);
                await _context.SaveChangesAsync();
            }



            return(pgs);
        }
        public async Task <ActionResult <PollGebruiker_dto> > PostPollGebruikerByUserIDAndPollID(PollGebruiker_dto pollGebruiker)
        {
            //als deze user al toegevoegd is aan poll -> null returnen
            //anders pollgebruiker toevoegen
            var pg = _context.PollGebruikers.FirstOrDefault(p => p.PollID == pollGebruiker.PollID && p.UserID == pollGebruiker.UserID);

            if (pg == null)
            {
                var pg1 = new PollGebruiker()
                {
                    UserID = pollGebruiker.UserID, PollID = pollGebruiker.PollID, isAdmin = pollGebruiker.isAdmin
                };
                _context.PollGebruiker.Add(pg1);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetPollGebruiker", new { id = pg1.PollGebruikerID }, pg1));
            }
            else
            {
                return(null);
            }
        }