Пример #1
0
        public ActionResult <Strawpoll> PutStrawpoll(int id, Strawpoll poll)
        {
            if (id != poll.StrawpollId)
            {
                return(BadRequest());
            }

            Strawpoll         pollDB = _strawpollRepository.GetById(id);
            IList <VotedUUID> voted  = new List <VotedUUID>();

            pollDB.DateCreated = poll.DateCreated;
            pollDB.Question    = poll.Question;
            pollDB.StrawpollId = poll.StrawpollId;

            poll.Answers.ToList().ForEach(e =>
            {
                Answer a       = _answerRepository.GetById(e.AnswerId);
                a.AmountVoted  = e.AmountVoted;
                a.AnswerString = e.AnswerString;
                _answerRepository.Update(a);
            });

            poll.AlreadyVoted.ToList().ForEach(e =>
            {
                VotedUUID a = _votedRepository.GetById(e.VotedUUIDId);
                if (a != null)
                {
                    a.UUID = e.UUID;
                    _votedRepository.Update(a);
                }
                else
                {
                    a = new VotedUUID(e.UUID);
                    _votedRepository.Add(a);
                }
                voted.Add(a);
            });

            pollDB.AlreadyVoted = voted;

            _strawpollRepository.Update(pollDB);
            _strawpollRepository.SaveChanges();
            return(CreatedAtAction(nameof(GetStrawpollById), new { id = poll.StrawpollId }, poll));
        }
Пример #2
0
 public void Update(VotedUUID vote)
 {
     _ctx.VotedUUIDs.Update(vote);
 }
Пример #3
0
 public void Add(VotedUUID vote)
 {
     _ctx.Add(vote);
 }