コード例 #1
0
        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");
        }
コード例 #2
0
		private void PreparePollModel(PollModel model, Poll poll, bool excludeProperties)
		{
			model.AvailableStores = _storeService.GetAllStores().Select(s => s.ToModel()).ToList();

			if (!excludeProperties)
			{
				if (poll != null)
					model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(poll);
				else
					model.SelectedStoreIds = new int[0];
			}

		}
コード例 #3
0
        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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
		public IList<Poll> Polls()
		{
			var defaultLanguage = _ctx.Set<Language>().FirstOrDefault();
			var poll1 = new Poll()
			{
				Language = defaultLanguage,
				Name = "How do you like the shop?",
				SystemKeyword = "RightColumnPoll",
				Published = 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,
			});


			//_pollAnswerRepository.Table.Where(x => x.DisplayOrder < 5).Each(y =>
			//    {
			//        poll1.PollAnswers.Add(y);
			//    });

			var poll2 = new Poll()
			{
				Language = defaultLanguage,
				Name = "How often do you buy online?",
				SystemKeyword = "RightColumnPoll",
				Published = true,
				DisplayOrder = 2,
			};

			poll2.PollAnswers.Add(new PollAnswer()
			{
				Name = "Daily",
				DisplayOrder = 1,
			});

			poll2.PollAnswers.Add(new PollAnswer()
			{
				Name = "Once a week",
				DisplayOrder = 2,
			});

			poll2.PollAnswers.Add(new PollAnswer()
			{
				Name = "Every two weeks",
				DisplayOrder = 3,
			});

			poll2.PollAnswers.Add(new PollAnswer()
			{
				Name = "Once a month",
				DisplayOrder = 4,
			});

			//_pollAnswerRepository.Table.Where(x => x.DisplayOrder > 4).Each(y =>
			//{
			//    poll2.PollAnswers.Add(y);
			//});


			var entities = new List<Poll>
			{
				poll1, poll2
			};

			this.Alter(entities);
			return entities;
		}
コード例 #6
0
 public static Poll ToEntity(this PollModel model, Poll destination)
 {
     return Mapper.Map(model, destination);
 }
コード例 #7
0
        /// <summary>
        /// Updates the poll
        /// </summary>
        /// <param name="poll">Poll</param>
        public virtual void UpdatePoll(Poll poll)
        {
            if (poll == null)
                throw new ArgumentNullException("poll");

            _pollRepository.Update(poll);

            //event notification
            _eventPublisher.EntityUpdated(poll);
        }
コード例 #8
0
        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
                    {
                        IpAddress = "192.168.1.1",
                        IsApproved = true,
                        CreatedOnUtc = new DateTime(2010, 01, 03),
                        UpdatedOnUtc = new DateTime(2010, 01, 04),
                        Customer = GetTestCustomer()
                    }
                );
            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();
        }