示例#1
0
        public static DTO.poll ToApp(this poll poll)
        {
            DTO.poll pollDTO = null;

            if (poll != null)
            {
                pollDTO = new DTO.poll();

                pollDTO.poll_id          = poll.poll_id;
                pollDTO.poll_description = poll.poll_description;
                pollDTO.views            = poll.views;

                foreach (var item in poll.option)
                {
                    pollDTO.options.Add(new optionDTO()
                    {
                        option_id          = item.option_id,
                        option_description = item.option_description,
                        qty = item.qty
                    });
                }
            }

            return(pollDTO);
        }
示例#2
0
 /// <summary>
 /// Valida os campos obrigatórios
 /// </summary>
 /// <param name="poll"></param>
 private void ValidarGetAll(DTO.poll poll)
 {
     if (poll == null)
     {
         throw new BusinessException("poll é obrigatório");
     }
 }
示例#3
0
        public static poll ToBd(this DTO.poll pollDTO)
        {
            poll poll = null;

            if (pollDTO != null)
            {
                poll = new poll();

                poll.poll_id          = pollDTO.poll_id;
                poll.poll_description = pollDTO.poll_description;
                poll.views            = pollDTO.views;

                foreach (var item in pollDTO.options)
                {
                    poll.option.Add(new option()
                    {
                        option_id          = item.option_id,
                        option_description = item.option_description,
                        qty = item.qty
                    });
                }
            }

            return(poll);
        }
示例#4
0
        public void Vote(DTO.poll poll)
        {
            var p = enqueteEntities.poll.FirstOrDefault(x => x.poll_id.Equals(poll.poll_id));

            p.option.FirstOrDefault(x => x.option_id.Equals(poll.options.FirstOrDefault().option_id)).qty++;

            enqueteEntities.SaveChanges();
        }
示例#5
0
        public long Poll(DTO.poll poll)
        {
            var p = pollTradutor.ToBd(poll);

            enqueteEntities.Entry(p).State = EntityState.Added;

            enqueteEntities.SaveChanges();

            return(p.poll_id);
        }
示例#6
0
        /// <summary>
        /// Valida os campos obrigatórios
        /// </summary>
        /// <param name="poll"></param>
        private void ValidarStats(DTO.poll poll)
        {
            if (poll == null)
            {
                throw new BusinessException("poll é obrigatório");
            }

            if (poll.poll_id <= 0)
            {
                throw new BusinessException("poll_id é obrigatório");
            }
        }
示例#7
0
        public DTO.poll Stats(DTO.poll poll)
        {
            var pollDTO = new DTO.poll();

            IQueryable <poll> query = enqueteEntities.poll;

            query = query.Where(x => x.poll_id.Equals(poll.poll_id));

            if (query.FirstOrDefault() != null)
            {
                pollDTO = pollTradutor.ToApp(query.FirstOrDefault());
            }

            return(pollDTO);
        }
示例#8
0
        /// <summary>
        /// Vota em uma poll
        /// </summary>
        /// <param name="poll"></param>
        public void Vote(DTO.poll poll)
        {
            try
            {
                ValidarVote(poll);

                pollRepository.Vote(poll);
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#9
0
        /// <summary>
        /// Cria uma nova poll
        /// </summary>
        /// <param name="poll"></param>
        /// <returns></returns>
        public long Poll(DTO.poll poll)
        {
            try
            {
                ValidarPoll(poll);

                return(pollRepository.Poll(poll));
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
        /// <summary>
        /// Valida os campos obrigatórios
        /// </summary>
        /// <param name="poll"></param>
        private void ValidarVote(DTO.poll poll)
        {
            if (poll == null)
            {
                throw new BusinessException("poll é obrigatório");
            }

            if (poll.poll_id <= 0)
            {
                throw new BusinessException("poll_id é obrigatório");
            }

            if (poll.options == null || poll.options.Count <= 0)
            {
                throw new BusinessException("options é obrigatório");
            }
        }
示例#11
0
        /// <summary>
        /// Valida os campos obrigatórios
        /// </summary>
        /// <param name="poll"></param>
        private void ValidarPoll(DTO.poll poll)
        {
            if (poll == null)
            {
                throw new BusinessException("poll é obrigatório");
            }

            if (string.IsNullOrEmpty(poll.poll_description))
            {
                throw new BusinessException("poll_description é obrigatório");
            }

            if (poll.options == null || poll.options.Count <= 0)
            {
                throw new BusinessException("options é obrigatório");
            }
        }
示例#12
0
        /// <summary>
        /// Estatísticas sobre uma poll
        /// </summary>
        /// <param name="poll"></param>
        /// <returns></returns>
        public DTO.poll Stats(DTO.poll poll)
        {
            try
            {
                ValidarStats(poll);

                return(pollRepository.Stats(poll));
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#13
0
        public DTO.poll Get(DTO.poll poll)
        {
            DTO.poll pollDTO = null;

            IQueryable <poll> query = enqueteEntities.poll;

            query = query.Where(x => x.poll_id.Equals(poll.poll_id));

            var p = query.FirstOrDefault();

            if (p != null)
            {
                p.views++;
                pollDTO = pollTradutor.ToApp(p);
                enqueteEntities.SaveChanges();
            }

            return(pollDTO);
        }
示例#14
0
        /// <summary>
        /// Lista as polls
        /// </summary>
        /// <param name="poll"></param>
        /// <returns></returns>
        public List <DTO.poll> GetAll(DTO.poll poll)
        {
            List <DTO.poll> pollsDTO = null;

            try
            {
                ValidarGetAll(poll);

                pollsDTO = pollRepository.GetAll(poll);
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(pollsDTO);
        }
示例#15
0
        /// <summary>
        /// Obtém uma poll
        /// </summary>
        /// <param name="poll"></param>
        /// <returns></returns>
        public DTO.poll Get(DTO.poll poll)
        {
            var pollDTO = new DTO.poll();

            try
            {
                ValidarGet(poll);

                pollDTO = pollRepository.Get(poll);
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                // log
                throw ex;
            }

            return(pollDTO);
        }
示例#16
0
        public List <DTO.poll> GetAll(DTO.poll poll)
        {
            List <DTO.poll> pollsDTO = new List <DTO.poll>();

            IQueryable <poll> query = enqueteEntities.poll;

            if (poll.poll_id > 0)
            {
                query = query.Where(x => x.poll_id.Equals(poll.poll_id));
            }

            if (!string.IsNullOrEmpty(poll.poll_description))
            {
                query = query.Where(x => x.poll_description.Contains(poll.poll_description));
            }

            foreach (var item in query)
            {
                pollsDTO.Add(pollTradutor.ToApp(item));
            }

            return(pollsDTO);
        }