/// <summary> /// Finds a poll option by idenitifer /// </summary> /// <returns>The specific poll options.</returns> /// <param name="ItemID">Unique item identifier.</param> public async Task <PollPart> FindPollOptionByID(int ItemID) { using (var client = this.client) { var content = await client.GetStringAsync(SharpHacker.MakeItemRequest(ItemID)); PollPart option = JsonConvert.DeserializeObject <PollPart>(content); return(option); } }
/// <summary> /// Gets the poll and sets the options object /// </summary> /// <returns>The poll with parts changed.</returns> /// <param name="poll">Poll to be changed.</param> /// <param name="oldClient">Old client to reuse.</param> private static async Task <Poll> SetParts(Poll poll, HttpClient oldClient) { using (var client = oldClient) { poll.Parts = new List <PollPart>(); if (poll.PartsID == null) { poll.PartsID = new List <int>(); } foreach (int ID in poll.PartsID) { var content = await client.GetStringAsync(SharpHacker.MakeItemRequest(ID)); PollPart pollPart = JsonConvert.DeserializeObject <PollPart>(content); poll.Parts.Add(pollPart); } return(poll); } }
public void CreatePoll(PollPart poll) { if (poll == null) { throw new ArgumentNullException("poll"); } var p = new PollPartRecord { ContentItemRecord = poll.Record.ContentItemRecord, Question = poll.Question, OpenDateUtc = poll.OpenDateUtc, CloseDateUtc = poll.CloseDateUtc, MaxVotes = poll.MaxVotes, Shown = poll.IsShown, MusicPoll = poll.IsMusicPoll, ShowVotingUI = poll.ShowVotingUI }; _pollRepository.Create(p); }
/// <summary> /// Private helper doing same as above but when HttpClient needs to be reused /// </summary> private async Task <Item> FindItemByID(int ItemID, HttpClient clientOld) { using (var client = clientOld) { var content = await client.GetStringAsync(SharpHacker.MakeItemRequest(ItemID)); Item item = JsonConvert.DeserializeObject <Item>(content); if (item.Dead || item.Deleted) { return(item); } else { switch (item.TypeItem) { case ItemType.Story: Story story = await SharpHacker.SetUpStory(JsonConvert.DeserializeObject <Story>(content)); return(story); case ItemType.Comment: Comment comment = JsonConvert.DeserializeObject <Comment>(content); return(comment); case ItemType.Poll: Poll poll = await SharpHacker.SetUpPoll(JsonConvert.DeserializeObject <Poll>(content)); return(poll); case ItemType.PollPart: PollPart pollPart = JsonConvert.DeserializeObject <PollPart>(content); return(pollPart); default: throw new ArgumentException("Item is deleted or nonexistent"); } } } }
public PollViewModel(PollPart part, IList <ChoiceEntry> choices) { if (part == null) { throw new ArgumentNullException("part"); } if (choices == null) { throw new ArgumentNullException("choices"); } bool isNew = part.Record.ContentItemRecord == null; Question = part.Record.Question == null ? "" : part.Record.Question; Open = part.Record.OpenDateUtc == null ? DateTime.Now : part.Record.OpenDateUtc.Value; Close = part.Record.CloseDateUtc == null?DateTime.Now.AddDays(14) : part.Record.CloseDateUtc.Value; MaxVotes = part.Record.MaxVotes; Shown = isNew ? true : part.Record.Shown; MusicPoll = part.Record.MusicPoll; ShowVotingUI = part.Record.ShowVotingUI; MusicPollInTestMode = part.Record.MusicPollInTestMode; Choices = choices == null ? new List <ChoiceEntry>() : choices; }
private void OnPollActivated(ActivatedContentContext context, PollPart part) { part.OptionsField.Loader(() => _pollService.GetOptions(part.Id).ToList()); part.SubmissionsField.Loader(() => _pollService.GetSubmissions(part.Id).ToList()); }
public void EditPoll(PollPart part, PollViewModel model) { if (part == null) { throw new ArgumentNullException("part"); } if (model == null) { throw new ArgumentNullException("model"); } var poll = new PollPartRecord { Id = part.Record.ContentItemRecord.Id, Question = model.Question, OpenDateUtc = model.Open, CloseDateUtc = model.Close, MaxVotes = model.MaxVotes, Shown = model.Shown, MusicPoll = model.MusicPoll, ShowVotingUI = model.ShowVotingUI, ContentItemRecord = part.Record.ContentItemRecord }; UpdatePoll(poll); foreach (var entry in model.Choices) { switch (entry.Action) { case "Alter": var choice = new PollChoiceRecord { Id = entry.Choice.Id, Answer = entry.Choice.Answer, PollPartRecord = part.Record }; UpdateChoice(choice); break; case "Create": if (entry.Choice.Answer != null && entry.Choice.Answer.Length > 0) { choice = new PollChoiceRecord { Answer = entry.Choice.Answer, PollPartRecord = part.Record }; CreateChoice(choice); } break; } } var choices = GetChoices(poll.Id).ToList(); var newChoices = model.Choices.Select(c => choices.FirstOrDefault(x => x.Id == c.Choice.Id || x.Answer == c.Choice.Answer)); var toDelete = choices.Except(newChoices); foreach (var choice in toDelete) { DeleteChoice(choice); } }
public void DeletePoll(PollPart poll) { _contentManager.Remove(poll.ContentItem); }