Beispiel #1
0
		private static Poll MapPollToModel(IPoll poll)
		{
			var result = new Poll();

			result.PollID = poll.PollID.Value;
			result.UserID = poll.UserID;
			result.PollCategoryID = poll.PollCategoryID.Value;
			result.PollQuestion = poll.PollQuestion;
			result.PollImageLink = poll.PollImageLink;
			result.PollMaxAnswers = poll.PollMaxAnswers.Value;
			result.PollMinAnswers = poll.PollMinAnswers.Value;
			result.PollStartDate = poll.PollStartDate;
			result.PollEndDate = poll.PollEndDate;
			result.PollAdminRemovedFlag = poll.PollAdminRemovedFlag.GetValueOrDefault(false);
			result.PollDateRemoved = poll.PollDateRemoved;
			result.PollDeletedFlag = poll.PollDeletedFlag.GetValueOrDefault(false);
			result.PollDeletedDate = poll.PollDeletedDate;
			result.PollDescription = poll.PollDescription;

			result.PollOptions = poll.PollOptions.Select(_ => new PollOption
			{
				PollOptionID = _.PollOptionID,
				PollID = _.PollID,
				OptionPosition = _.OptionPosition,
				OptionText = _.OptionText
			}).ToList();

			return result;
		}
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;
		}