public async Task <List <PollOptions> > CreateOptionsWithIdAsync(string[] options)
        {
            if (options[0] != null)
            {
                if (options[0].Contains(","))
                {
                    var options2 = options[0].Split(',').Reverse().ToArray();
                    options = options2;
                }
            }

            var pollOptions      = new List <PollOptions>();
            var sequenceOptionId = await SequenceOptionIdAsync();

            for (int i = 0; i < options.Count(); i++)
            {
                var pollOption = new PollOptions()
                {
                    OptionId          = sequenceOptionId + i,
                    OptionDescription = options[i]
                };

                pollOptions.Add(pollOption);
            }

            return(pollOptions);
        }
Ejemplo n.º 2
0
        public IActionResult AddNewPoll([FromBody] NewPollViewModel newPoll)
        {
            string userId = Request.Headers[Constants.UserToken];
            User   user;

            _memoryCache.TryGetValue(userId, out user);
            if (user == null)
            {
                return(Unauthorized(Messages.UserNotFoundError));
            }

            Poll p = _mapper.Map <Poll>(newPoll);

            p.CreatedDate = DateTime.UtcNow;
            p.CreatedBy   = user.Userid;

            _dBContext.Poll.Add(p);
            _dBContext.SaveChanges();

            List <PollOptions> lstPollOptions = new List <PollOptions>();

            int order = 0;

            foreach (var item in newPoll.options)
            {
                PollOptions options = new PollOptions();
                options.PollId      = p.PollId;
                options.OptionText  = item;
                options.StatusId    = p.StatusId;
                options.CreatedBy   = user.Userid;
                options.CreatedDate = DateTime.UtcNow;
                options.OrderId     = order;
                lstPollOptions.Add(options);
                order++;
            }

            _dBContext.PollOptions.AddRange(lstPollOptions);
            _dBContext.SaveChanges();

            PollViewModel pCache = _mapper.Map <PollViewModel>(p);

            pCache.PollOptions = lstPollOptions;

            _memoryCache.Set($"dbpoll_id_{p.PollId}", p);
            _memoryCache.Set($"poll_guid_{p.PollGuid}", pCache);
            _memoryCache.Set($"poll_id_{p.PollId}", pCache);
            _memoryCache.Remove($"poll_userpoll_userid_{user.UserGuid}");

            DashboardMetricsViewModel dashboardMetricsViewModel;

            _memoryCache.TryGetValue($"dashboard_{user.UserGuid}", out dashboardMetricsViewModel);
            if (dashboardMetricsViewModel != null)
            {
                dashboardMetricsViewModel.polls += 1;
                _memoryCache.Set($"dashboard_{user.UserGuid}", dashboardMetricsViewModel);
            }

            return(GetPoll(p.PollId));
        }
Ejemplo n.º 3
0
        public ActionResult Index(string answer)
        {
            PollOptions pollOptions = unitOfWork.PollOptionsRepository.Get().FirstOrDefault(p => p.Answer == answer);

            pollOptions.Votes++;
            unitOfWork.Save();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
 internal Poll(RestUserMessage message, string title, SocketUser usr, params string[] options)
 {
     PollCreator = usr;
     PollMessage = message;
     PollTitle   = title;
     PollId      = GetNextId();
     for (int i = 1; i <= options.Length; i++)
     {
         Emoji e = new Emoji($"{i.ToString()}\u20E3");
         PollOptions.Add(new PollOption(options[i - 1], e));
     }
 }
Ejemplo n.º 5
0
 internal bool?RemoveReaction(SocketUser usr, string vote)
 {
     if (PollOptions.Where(x => x.Option == vote) == null)
     {
         return(null);
     }
     if (PollReactions.Where(x => x.User.Id == usr.Id) == null)
     {
         return(false);
     }
     PollReactions.Remove(PollReactions.Single(x => x.User.Id == usr.Id && x.PollVote == vote));
     return(true);
 }
Ejemplo n.º 6
0
 internal bool?AddReaction(SocketUser usr, string vote)
 {
     if (PollOptions.Where(x => x.Option == vote) == null)
     {
         return(null);
     }
     if (PollReactions.Where(x => x.User.Id == usr.Id) == null)
     {
         return(false);
     }
     PollReactions.Add(new PollReaction(usr, vote));
     return(true);
 }
Ejemplo n.º 7
0
 private void AddOption()
 {
     if (PollOptions.Count < 10)
     {
         PollOptions.Add(new Option()
         {
             PollID = CreatedPollID, OptionID = CreatedPollID.Substring(0, 8) + "_" + optionsCounter++, OptionPlaceHolder = "Option " + (optionsCounter).ToString()
         });
         //optionsCounter++;
     }
     else
     {
         Application.Current.MainPage.DisplayAlert("Cannot Add Option", "You have reached the maximum number of options.", "Ok");
     }
 }
Ejemplo n.º 8
0
        public IActionResult AddNewPoll([FromBody] NewPollViewModel newPoll)
        {
            string userId        = Request.Headers[Constants.UserToken];
            string decyrptstring = Security.Decrypt(userId);

            if (decyrptstring == null)
            {
                return(BadRequest());
            }

            User user = _dBContext.User.Where(x => x.UserGuid == decyrptstring).FirstOrDefault();

            if (user == null)
            {
                return(BadRequest(Messages.UserNotFoundError));
            }

            Poll p = _mapper.Map <Poll>(newPoll);

            p.CreatedDate = DateTime.UtcNow;
            p.CreatedBy   = user.Userid;

            _dBContext.Poll.Add(p);
            _dBContext.SaveChanges();

            List <PollOptions> lstPollOptions = new List <PollOptions>();

            int order = 0;

            foreach (var item in newPoll.options)
            {
                PollOptions options = new PollOptions();
                options.PollId      = p.PollId;
                options.OptionText  = item;
                options.StatusId    = p.StatusId;
                options.CreatedBy   = user.Userid;
                options.CreatedDate = DateTime.UtcNow;
                options.OrderId     = order;
                lstPollOptions.Add(options);
                order++;
            }

            _dBContext.PollOptions.AddRange(lstPollOptions);
            _dBContext.SaveChanges();
            return(GetPoll(p.PollId));
        }
Ejemplo n.º 9
0
 private void RemoveOption(string s)
 {
     Console.WriteLine("Trying to remove option");
     if (PollOptions.Count <= 2)
     {
         Application.Current.MainPage.DisplayAlert("Cannot Remove Option", "There must be at least 2 options in a poll!", "Ok");
     }
     else
     {
         var item = PollOptions.SingleOrDefault(x => x.OptionPlaceHolder == s);
         if (item != null)
         {
             PollOptions.Remove(item);
             item = null;
         }
     }
 }
Ejemplo n.º 10
0
        protected override void Seed(MyBlogContext context)
        {
            Post firstPost = new Post {
                AuthorName = "Jaap Schekkerman ", PostId = 1, Title = "How to survive in enterprise", PostDate = new DateTime(2018, 10, 10), PostBody = "Several times in my Enterprise Architecture(EA) practice,people asked me which framework shall I adopt or what are the benefits of the Zachman framework over TOGAF etc.Others asked me to help them to define their own corporate EA framework.Before answering these types of questions,      it is important to know what the differences and commonalities are of these frameworks and standards.Several times in my Enterprise Architecture(EA) practice,people asked me which framework shall I adopt or what are the benefits of the Zachman framework over TOGAF etc.Others asked me to help them to define their own corporate EA framework.Before answering these types of questions,      it is important to know what the differences and commonalities are of these frameworks and standards.", PostTag = "Enterprice"
            };
            Post secondPost = new Post {
                AuthorName = "Mark Gibbs", PostId = 2, Title = "How to survive in IT", PostDate = new DateTime(2018, 10, 10), PostBody = "So you have decided on a career in IT instead of, say, being a dancer on Broadway or becoming a fugu chef in Japan. Given that you consider IT more interesting than appearing in 50,000 performances of Oliver and less risky than serving up potentially lethal sushi, what should you know about not just surviving but prospering in the fast paced and exciting world of information technology?So you have decided on a career in IT instead of, say, being a dancer on Broadway or becoming a fugu chef in Japan. Given that you consider IT more interesting than appearing in 50,000 performances of Oliver and less risky than serving up potentially lethal sushi, what should you know about not just surviving ", PostTag = "IT"
            };

            context.Posts.Add(firstPost);
            context.Posts.Add(secondPost);

            Comment firstComment = new Comment {
                CommentAuthorName = "Jane Doe", CommentDate = new DateTime(2018, 10, 10), CommentId = 1, PostID = 1, CommentBody = "Thanks for a good useful post!"
            };
            Comment secondComment = new Comment {
                CommentAuthorName = "John Dow", CommentDate = new DateTime(2018, 10, 10), CommentId = 2, PostID = 2, CommentBody = "Really useful,thanks.Cheers!"
            };

            context.Comments.Add(firstComment);
            context.Comments.Add(secondComment);

            Poll poll = new Poll {
                Question = "Котики или собачки?"
            };

            context.Polls.Add(poll);

            PollOptions polloptions = new PollOptions {
                Answer = "Котики", Votes = 0, Polls = poll
            };

            context.PollsOptions.Add(polloptions);
            polloptions = new PollOptions {
                Answer = "Собачки", Votes = 0, Polls = poll
            };

            context.PollsOptions.Add(polloptions);

            base.Seed(context);
            context.SaveChanges();
        }