/// <summary>
        /// Set a poll definition to published/unpublished
        /// </summary>
        /// <param name="id"></param>
        /// <param name="isPublished"></param>
        /// <returns>bool</returns>
        ///
        public async Task <bool> SetPublishedStatusAsync(int id, bool isPublished)
        {
            var pollDefinition = await _context.PollDefinitions.FindAsync(id);

            if (pollDefinition == null)
            {
                throw new PollDefNotFoundException();
            }

            pollDefinition.IsPublished           = isPublished;
            _context.Entry(pollDefinition).State = EntityState.Modified;

            try
            {
                return(await _context.SaveChangesAsync() > 0);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PollDefinitionExists(id))
                {
                    throw new PollDefNotFoundException();
                }
                else
                {
                    throw;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Set the poll status to open to voting
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <bool> OpenPollAsync(int id)
        {
            var poll = await _context.Polls
                       .Where(p => p.Id == id)
                       .Include(q => q.Questions)
                       .ThenInclude(a => a.Answers)
                       .FirstOrDefaultAsync();

            if (poll == null)
            {
                throw new PollNotFoundException();
            }

            poll.Status = PollStatus.Open;
            _context.Entry(poll).State = EntityState.Modified;

            return(await _context.SaveChangesAsync() > 0);
        }