Beispiel #1
0
        private IPoll SavePoll(Poll input, IPoll poll)
        {
            poll.PollCategoryID       = input.PollCategoryID;
            poll.PollQuestion         = input.PollQuestion;
            poll.PollImageLink        = input.PollImageLink;
            poll.PollMaxAnswers       = input.PollMaxAnswers;
            poll.PollMinAnswers       = input.PollMinAnswers;
            poll.PollStartDate        = input.PollStartDate;
            poll.PollEndDate          = input.PollEndDate;
            poll.PollAdminRemovedFlag = input.PollAdminRemovedFlag;
            poll.PollDateRemoved      = input.PollDateRemoved;
            poll.PollDeletedFlag      = input.PollDeletedFlag;
            poll.PollDeletedDate      = input.PollDeletedDate;
            poll.PollDescription      = input.PollDescription;

            // remove items from the real poll if they aren't in the input
            if (input.PollOptions == null)
            {
                poll.PollOptions.Clear();
            }
            else
            {
                var toRemove = new List <IPollOption>();
                toRemove.AddRange(
                    poll.PollOptions.Where(item => input.PollOptions.All(_ => _.PollOptionID != item.PollOptionID)));
                foreach (var item in toRemove)
                {
                    poll.PollOptions.Remove(item);
                }
            }

            // add or update according to new options list
            if (input.PollOptions != null && input.PollOptions.Count > 0)
            {
                var toAdd = new List <IPollOption>();

                foreach (var item in input.PollOptions)
                {
                    var existing = poll.PollOptions.FirstOrDefault(_ => _.PollOptionID == item.PollOptionID);
                    if (existing == null)
                    {
                        var newOption = this.PollOptionFactory.Value.CreateChild();
                        newOption.OptionPosition = item.OptionPosition;
                        newOption.OptionText     = item.OptionText;
                        toAdd.Add(newOption);
                    }
                    else
                    {
                        // updating existing item
                        existing.OptionPosition = item.OptionPosition;
                        existing.OptionText     = item.OptionText;
                    }
                }

                poll.PollOptions.AddRange(toAdd);
            }

            return(poll.Save() as IPoll);
        }
Beispiel #2
0
		private IPoll SavePoll(Poll input, IPoll poll)
		{
			poll.PollCategoryID = input.PollCategoryID;
			poll.PollQuestion = input.PollQuestion;
			poll.PollImageLink = input.PollImageLink;
			poll.PollMaxAnswers = input.PollMaxAnswers;
			poll.PollMinAnswers = input.PollMinAnswers;
			poll.PollStartDate = input.PollStartDate;
			poll.PollEndDate = input.PollEndDate;
			poll.PollAdminRemovedFlag = input.PollAdminRemovedFlag;
			poll.PollDateRemoved = input.PollDateRemoved;
			poll.PollDeletedFlag = input.PollDeletedFlag;
			poll.PollDeletedDate = input.PollDeletedDate;
			poll.PollDescription = input.PollDescription;

			// remove items from the real poll if they aren't in the input
			if (input.PollOptions == null)
			{
				poll.PollOptions.Clear();
			}
			else
			{
				var toRemove = new List<IPollOption>();
				toRemove.AddRange(
					poll.PollOptions.Where(item => input.PollOptions.All(_ => _.PollOptionID != item.PollOptionID)));
				foreach (var item in toRemove)
				{
					poll.PollOptions.Remove(item);
				}
			}

			// add or update according to new options list
			if (input.PollOptions != null && input.PollOptions.Count > 0)
			{
				var toAdd = new List<IPollOption>();

				foreach (var item in input.PollOptions)
				{
					var existing = poll.PollOptions.FirstOrDefault(_ => _.PollOptionID == item.PollOptionID);
					if (existing == null)
					{
						var newOption = this.PollOptionFactory.Value.CreateChild();
						newOption.OptionPosition = item.OptionPosition;
						newOption.OptionText = item.OptionText;
						toAdd.Add(newOption);
					}
					else
					{
						// updating existing item
						existing.OptionPosition = item.OptionPosition;
						existing.OptionText = item.OptionText;
					}
				}

				poll.PollOptions.AddRange(toAdd);
			}

			return poll.Save() as IPoll;
		}