Beispiel #1
0
        public async Task <PollCreated> CreatePoll(PollCreate pollCreate)
        {
            //TODO Category Repository
            var generatedCode = await _codeService.GenerateCode();

            int catId = 1;

            var poll = new PollEntity
            {
                Title    = pollCreate.Title,
                Category = new CategoryEntity
                {
                    Id   = catId,
                    Name = pollCreate.Category
                },
                Code = generatedCode
            };

            await _pollRepository.InsertPollAsync(poll);

            return(new PollCreated
            {
                Code = generatedCode.Code
            });
        }
        public PollEntity AddNewPollAndReturnPoll(PollModelView pollModelView, ApplicationUser applicationUser, ApplicationDbContext db)
        {
            var pollEntity = new PollEntity(pollModelView, applicationUser);

            db.Polls.Add(pollEntity);
            db.SaveChanges();
            return(pollEntity);
        }
        public Task InsertPollAsync(PollEntity poll)
        {
            poll.Id = _polls.Count;
            Task query = new Task(() => InsertPoll(poll));

            query.Start();

            return(query);
        }
Beispiel #4
0
 private TeamRankingBE getEntity(PollEntity pe, bool chart)
 {
     return(pe == null ? null : new TeamRankingBE
     {
         Date = chart ? pe.chart_date : pe.date,
         Datestr = chart ? pe.chart_date.ToString("MMMM dd, yyyy") : pe.date.ToString("MMMM dd, yyyy"),
         pollSource = pe.pollsource_id,
         Rank = pe.rank,
         Url = pe.url
     });
 }
Beispiel #5
0
        private PollEntity GetPollEntity(TeamRankingBE mclaPoll)
        {
            var pe = new PollEntity
            {
                date          = mclaPoll.Date,
                pollsource_id = mclaPoll.pollSource,
                rank          = mclaPoll.Rank,
                url           = mclaPoll.Url
            };

            return(pe);
        }
 private bool IsPrivPollAuthorised(PollEntity poll)
 {
     if (!string.IsNullOrEmpty(poll.Password))
     {
         var controller = DependencyResolver.Current.GetService <PrivatePollController>();
         controller.ControllerContext = new ControllerContext(Request.RequestContext, this);
         return(controller.IsRequestAuthorised(poll));
     }
     else
     {
         return(true);
     }
 }
        //Create new session in datebase and return cookie
        public HttpCookie GetSessionCookie(ApplicationDbContext db, PollEntity poll)
        {
            var idSession = Guid.NewGuid();

            db.SessionPrivatePoll.Add(new SessionUserPrivatePollEntity()
            {
                SessionID = idSession, DateTime = DateTime.Now, Poll = poll
            });
            var cookie = new HttpCookie("privPoll");

            cookie.Expires = DateTime.Now.AddMinutes(sessionTimeoutMinute);
            cookie.Value   = idSession.ToString();
            db.SaveChanges();
            return(cookie);
        }
        private ActionResult GetPollAndReturnView(string nameOfView, int id)
        {
            PollEntity poll = db.Polls.Find(id);

            if (poll == null)
            {
                return(new HttpStatusCodeResult(404));             //check if the poll exists
            }
            if (!IsPrivPollAuthorised(poll))
            {
                return(RedirectToAction("PrivatePollAuth", "PrivatePoll", new { id }));
            }
            poll.View++;
            db.SaveChanges();
            return(View(nameOfView, poll));
        }
Beispiel #9
0
        public async Task StartAsync(UpdateMessage message)
        {
            var callbackQueryData = message.CallbackQuery.Data.Split(';');
            var occasionId        = callbackQueryData[1];

            var occasion = _occasionRepository.FindById(occasionId);

            if (occasion == null)
            {
                return;
            }

            var activePolls = _pollRepository.Find(x => x.ChatId == occasion.ChatId && !x.IsClosed).ToList();

            if (activePolls.Any())
            {
                await _telegramClient.SendMessageAsync(new SendMessage
                {
                    ChatId = occasion.ChatId,
                    Text   = Messages.ActivePollRunning
                });

                return;
            }

            var sendPollMessage = TelegramMessageFactory.CreateSendPollMessage(occasion.ChatId, occasion.Name);
            var pollMessage     = await _telegramClient.SendPollAsync(sendPollMessage);

            var entity = new PollEntity
            {
                PartitionKey = occasion.ChatId,
                RowKey       = pollMessage.Poll.Id,
                Timestamp    = _dateTimeService.TableEntityTimeStamp,
                ChatId       = occasion.ChatId,
                OccasionId   = occasionId,
                MessageId    = pollMessage.MessageId.ToString(),
                IsClosed     = false
            };

            await _pollRepository.CreateAsync(entity);

            await _telegramClient.AnswerCallbackQuery(new AnswerCallbackQuery
            {
                CallBackQueryId = message.CallbackQuery.Id,
                Text            = Messages.PollStarted
            });
        }
        private Poll MapPollEntity(PollEntity pollEntity)
        {
            var mappedPoll = new Poll()
            {
                Id = pollEntity.Id, Name = pollEntity.Name, PollEnd = pollEntity.PollEnd
            };

            foreach (var pollOptionEntity in pollEntity.PollOptions)
            {
                mappedPoll.PollOptions.Add(new PollOption()
                {
                    Id = pollOptionEntity.Id, Name = pollOptionEntity.Name, Votes = pollOptionEntity.Votes
                });
            }

            return(mappedPoll);
        }
        public bool IsRequestAuthorised(PollEntity poll)
        {
            var user = appUserManager.FindById(User.Identity.GetUserId());

            if (user != null && poll.UserCreator.Id == user.Id)
            {
                return(true);                                             //creator of poll always has access
            }
            var privatePollManager = new PrivatePollManager();

            if (Request.Cookies["privPoll"] != null && privatePollManager.IsAuthorisedByCookie(Request.Cookies["privPoll"].Value, db))
            {
                Request.Cookies["privPoll"].Expires = DateTime.Now.AddMinutes(10);//updating cookie
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private PollEntity MapPoll(Poll poll)
        {
            var mappedPollEntity = new PollEntity()
            {
                Id = poll.Id, Name = poll.Name, PollEnd = poll.PollEnd
            };

            var pollOptionEntities = new List <PollOptionEntity>();

            foreach (var pollOption in poll.PollOptions)
            {
                pollOptionEntities.Add(new PollOptionEntity()
                {
                    Id = pollOption.Id, Name = pollOption.Name, Votes = pollOption.Votes
                });
            }

            mappedPollEntity.PollOptions = pollOptionEntities;

            return(mappedPollEntity);
        }
Beispiel #13
0
 private void InsertPoll(PollEntity poll)
 {
     _polls.Add(poll);
 }