public void Can_save_and_load_poll()
        {
            var poll = new Poll
            {
                Name = "Name 1",
                SystemKeyword = "SystemKeyword 1",
                Published = true,
                ShowOnHomePage = true,
                DisplayOrder = 1,
                StartDateUtc = new DateTime(2010, 01, 01),
                EndDateUtc = new DateTime(2010, 01, 02),
                Language = new Language()
                {
                    Name = "English",
                    LanguageCulture = "en-Us",
                }
            };

            var fromDb = SaveAndLoadEntity(poll);
            fromDb.ShouldNotBeNull();
            fromDb.Name.ShouldEqual("Name 1");
            fromDb.SystemKeyword.ShouldEqual("SystemKeyword 1");
            fromDb.Published.ShouldEqual(true);
            fromDb.ShowOnHomePage.ShouldEqual(true);
            fromDb.DisplayOrder.ShouldEqual(1);
            fromDb.StartDateUtc.ShouldEqual(new DateTime(2010, 01, 01));
            fromDb.EndDateUtc.ShouldEqual(new DateTime(2010, 01, 02));

            fromDb.Language.ShouldNotBeNull();
            fromDb.Language.Name.ShouldEqual("English");
        }
        public void Can_save_and_load_poll_with_answers()
        {
            var poll = new Poll
            {
                Name = "Name 1",
                SystemKeyword = "SystemKeyword 1",
                Published = true,
                ShowOnHomePage = true,
                DisplayOrder = 1,
                StartDateUtc = new DateTime(2010, 01, 01),
                EndDateUtc = new DateTime(2010, 01, 02),
                Language = new Language()
                {
                    Name = "English",
                    LanguageCulture = "en-Us",
                }
            };
            poll.PollAnswers.Add
                (
                    new PollAnswer
                    {
                        Name = "Answer 1",
                        NumberOfVotes = 1,
                        DisplayOrder = 2,
                    }
                );
            var fromDb = SaveAndLoadEntity(poll);
            fromDb.ShouldNotBeNull();

            fromDb.PollAnswers.ShouldNotBeNull();
            (fromDb.PollAnswers.Count == 1).ShouldBeTrue();
            fromDb.PollAnswers.First().Name.ShouldEqual("Answer 1");
            fromDb.PollAnswers.First().NumberOfVotes.ShouldEqual(1);
            fromDb.PollAnswers.First().DisplayOrder.ShouldEqual(2);
        }
        /// <summary>
        /// Deletes a poll
        /// </summary>
        /// <param name="poll">The poll</param>
        public virtual void DeletePoll(Poll poll)
        {
            if (poll == null)
                throw new ArgumentNullException("poll");

            _pollRepository.Delete(poll);

            //event notification
            _eventPublisher.EntityDeleted(poll);
        }
Exemple #4
0
        /// <summary>
        /// Deletes a poll
        /// </summary>
        /// <param name="poll">The poll</param>
        public virtual void DeletePoll(Poll poll)
        {
            if (poll == null)
                throw new ArgumentNullException("poll");

            _pollRepository.Delete(poll);

            _cacheManager.RemoveByPattern(POLLS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityDeleted(poll);
        }
        protected PollModel PreparePollModel(Poll poll, bool setAlreadyVotedProperty)
        {
            var model = new PollModel()
            {
                Id = poll.Id,
                AlreadyVoted = setAlreadyVotedProperty && _pollService.AlreadyVoted(poll.Id, _workContext.CurrentCustomer.Id),
                Name = poll.Name
            };
            var answers = poll.PollAnswers.OrderBy(x => x.DisplayOrder);
            foreach (var answer in answers)
                model.TotalVotes += answer.NumberOfVotes;
            foreach (var pa in answers)
            {
                model.Answers.Add(new PollAnswerModel()
                {
                    Id = pa.Id,
                    Name = pa.Name,
                    NumberOfVotes = pa.NumberOfVotes,
                    PercentOfTotalVotes = model.TotalVotes > 0 ? ((Convert.ToDouble(pa.NumberOfVotes) / Convert.ToDouble(model.TotalVotes)) * Convert.ToDouble(100)) : 0,
                });
            }

            return model;
        }
 public static Poll ToEntity(this PollModel model, Poll destination)
 {
     return Mapper.Map(model, destination);
 }
        protected virtual void InstallPolls()
        {
            var defaultLanguage = _languageRepository.Table.FirstOrDefault();
            var poll1 = new Poll
            {
                Id = 1,
                LanguageId = defaultLanguage.Id,
                Name = "Do you like Grandnode for MongoDB?",
                SystemKeyword = "",
                Published = true,
                ShowOnHomePage = true,
                DisplayOrder = 1,
            };
            poll1.PollAnswers.Add(new PollAnswer
            {
                Name = "Excellent",
                DisplayOrder = 1,
                PollId = 1,
                Id = 1,
                _id = ObjectId.GenerateNewId().ToString(),
            });
            poll1.PollAnswers.Add(new PollAnswer
            {
                Name = "Good",
                DisplayOrder = 2,
                PollId = 1,
                Id = 2,
                _id = ObjectId.GenerateNewId().ToString(),
            });
            poll1.PollAnswers.Add(new PollAnswer
            {
                Name = "Poor",
                DisplayOrder = 3,
                PollId = 1,
                Id = 3,
                _id = ObjectId.GenerateNewId().ToString(),

            });
            poll1.PollAnswers.Add(new PollAnswer
            {
                Name = "Very bad",
                DisplayOrder = 4,
                PollId = 1,
                Id = 4,
                _id = ObjectId.GenerateNewId().ToString(),

            });
            _pollRepository.Insert(poll1);
        }
        public void Can_save_and_load_poll_with_answer_and_votingrecord()
        {
            var poll = new Poll
            {
                Name = "Name 1",
                SystemKeyword = "SystemKeyword 1",
                Published = true,
                ShowOnHomePage = true,
                DisplayOrder = 1,
                StartDateUtc = new DateTime(2010, 01, 01),
                EndDateUtc = new DateTime(2010, 01, 02),
                Language = new Language()
                {
                    Name = "English",
                    LanguageCulture = "en-Us",
                }
            };
            poll.PollAnswers.Add
                (
                    new PollAnswer
                    {
                        Name = "Answer 1",
                        NumberOfVotes = 1,
                        DisplayOrder = 2,
                    }
                );
            poll.PollAnswers.First().PollVotingRecords.Add
                (
                    new PollVotingRecord
                    {
                        Customer = GetTestCustomer(),
                        CreatedOnUtc = DateTime.UtcNow
                    }
                );
            var fromDb = SaveAndLoadEntity(poll);
            fromDb.ShouldNotBeNull();


            fromDb.PollAnswers.ShouldNotBeNull();
            (fromDb.PollAnswers.Count == 1).ShouldBeTrue();

            fromDb.PollAnswers.First().PollVotingRecords.ShouldNotBeNull();
            (fromDb.PollAnswers.First().PollVotingRecords.Count == 1).ShouldBeTrue();
        }
 protected virtual void InstallPolls()
 {
     var defaultLanguage = _languageRepository.Table.FirstOrDefault();
     var poll1 = new Poll
     {
         Language = defaultLanguage,
         Name = "Do you like nopCommerce?",
         SystemKeyword = "",
         Published = true,
         ShowOnHomePage = true,
         DisplayOrder = 1,
     };
     poll1.PollAnswers.Add(new PollAnswer
     {
         Name = "Excellent",
         DisplayOrder = 1,
     });
     poll1.PollAnswers.Add(new PollAnswer
     {
         Name = "Good",
         DisplayOrder = 2,
     });
     poll1.PollAnswers.Add(new PollAnswer
     {
         Name = "Poor",
         DisplayOrder = 3,
     });
     poll1.PollAnswers.Add(new PollAnswer
     {
         Name = "Very bad",
         DisplayOrder = 4,
     });
     _pollRepository.Insert(poll1);
 }