Example #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);
        }
Example #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");
     }
 }
Example #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);
        }
        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();
        }
        public long Poll(DTO.poll poll)
        {
            var p = pollTradutor.ToBd(poll);

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

            enqueteEntities.SaveChanges();

            return(p.poll_id);
        }
Example #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");
            }
        }
        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);
        }
Example #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;
            }
        }
Example #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;
            }
        }
Example #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");
            }
        }
Example #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");
            }
        }
Example #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;
            }
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }