public static PollOptionModel SavePollOptionConfiguration(PollOptionModel model) { PollOptionModel response = model; model.AlertType = AlertType.Error; spiffaiwebEntities db = new spiffaiwebEntities(); try { var option = new PollOption { PollId = model.PollId, PollOptionTitle = model.PollOptionTitle, PollOptionDescription = model.PollOptionDescription, PollOptionUrl = model.PollOptionUrl, }; if (model.PollOptionId > 0) { //Edit option.PollOptionId = model.PollOptionId; db.Entry(option).State = EntityState.Modified; db.SaveChanges(); model.AlertType = AlertType.Success; } else { //Create Poll Option db.PollOptions.Add(option); db.SaveChanges(); model.AlertType = AlertType.Success; response.PollOptionId = option.PollOptionId; //Add to VoteCount var voteCount = new PollVoteCount { PollId = model.PollId, PollOptionId = option.PollOptionId, PollOptionVoteTotal = 0 }; db.PollVoteCounts.Add(voteCount); db.SaveChanges(); } } catch (Exception) { throw; } return response; }
public static bool SavePollVoteCount(int pollId, int pollOptionId) { bool success = false; spiffaiwebEntities db = new spiffaiwebEntities(); //Update PollVoteCount PollVoteCountModel response = GetPollVoteCountModel(pollId, pollOptionId); if (response.PollVoteCountId > 0) { var voteCount = new PollVoteCount(); voteCount.PollVoteCountId = response.PollVoteCountId; voteCount.PollId = pollId; voteCount.PollOptionId = pollOptionId; voteCount.PollOptionVoteTotal = response.PollOptionVoteTotal; db.Entry(voteCount).State = EntityState.Modified; db.SaveChanges(); success = true; } else { //Add to VoteCount var voteCount = new PollVoteCount { PollId = pollId, PollOptionId = pollOptionId, PollOptionVoteTotal = 1 }; db.PollVoteCounts.Add(voteCount); db.SaveChanges(); success = true; } return success; }