public byte[] ExportToXml(int poll_id)
        {
            var poll    = _pollRepository.Get(poll_id);
            var choices = _choiceRepository.Fetch(c => c.PollPartRecord.Id == poll_id).AsQueryable();
            var results = _resultRepository.Fetch(r => r.PollChoiceRecord.PollPartRecord.Id == poll_id);

            StringBuilder sb    = new StringBuilder(); //TODO: Not used?
            var           entry = new PollEntry
            {
                Question     = poll.Question,
                OpenDateUtc  = poll.OpenDateUtc.Value,
                CloseDateUtc = poll.CloseDateUtc.Value,
                MaxVotes     = poll.MaxVotes,
                IsShown      = poll.Shown,
                IsMusicPoll  = poll.MusicPoll,
                ShowVotingUI = poll.ShowVotingUI,
                Choices      = results.Select(r => new PollEntry.Choice
                {
                    Answer = r.PollChoiceRecord.Answer,
                    Count  = r.Count
                }).ToList()
            };
            XmlSerializer serializer = new XmlSerializer(typeof(PollEntry));
            MemoryStream  ms         = new MemoryStream();
            XmlWriter     writer     = XmlWriter.Create(ms, new XmlWriterSettings()
            {
                CheckCharacters = true
            });

            serializer.Serialize(writer, entry);
            return(ms.ToArray());
        }
        public static void SavePoll(PollEntry input, int round, int pollId, string membershipId)
        {
            IPollEntryRepository pollRepo = new EFPollEntriesRepository();
            var dbPoll = pollRepo.PollEntries.FirstOrDefault(p => p.OwnerMembershipId == membershipId && p.PollId == pollId);

            if (dbPoll == null)
            {
                dbPoll = new PollEntry();
                dbPoll.OwnerMembershipId = membershipId;
                dbPoll.PollId            = pollId;
            }

            dbPoll.Num1 = input.Num1;
            dbPoll.Num2 = input.Num2;
            dbPoll.Num3 = input.Num3;
            dbPoll.Num4 = input.Num4;
            dbPoll.Num5 = input.Num5;

            dbPoll.String1 = input.String1;
            dbPoll.String2 = input.String2;
            dbPoll.String3 = input.String3;
            dbPoll.String4 = input.String4;
            dbPoll.String5 = input.String5;

            dbPoll.Timestamp = DateTime.UtcNow;

            pollRepo.SavePollEntry(dbPoll);
        }
        public static PollEntry LoadPoll(int pollId, string membershipId)
        {
            IPollEntryRepository pollRepo = new EFPollEntriesRepository();
            var dbPoll = pollRepo.PollEntries.FirstOrDefault(p => p.OwnerMembershipId == membershipId && p.PollId == pollId);

            if (dbPoll == null)
            {
                dbPoll        = new PollEntry();
                dbPoll.PollId = pollId;
            }
            return(dbPoll);
        }
Beispiel #4
0
        public virtual ActionResult ReplyToPoll(PollEntry input)
        {
            var myMembershipId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                ViewBag.Error = "Invalid input.";
                // TODO: T4ize
                return(View("Polls/Open/poll" + input.PollId, input));
            }

            SettingsProcedures.SavePoll(input, 14, input.PollId, myMembershipId);
            TempData["Result"] = "Your response has been recorded.  Thanks for your participation!";
            return(RedirectToAction(MVC.PvP.Play()));
        }
 public void SavePollEntry(PollEntry PollEntries)
 {
     if (PollEntries.Id == 0)
     {
         context.PollEntries.Add(PollEntries);
     }
     else
     {
         var editMe = context.PollEntries.Find(PollEntries.Id);
         if (editMe != null)
         {
             // dbEntry.Name = PollEntries.Name;
             // dbEntry.Message = PollEntries.Message;
             // dbEntry.TimeStamp = PollEntries.TimeStamp;
         }
     }
     context.SaveChanges();
 }