Example #1
0
        public static void CreateNewPoll(string question, string answer1, 
			string answer2, string answer3, string answer4, string answer5, string answer6)
        {
            Poll newPoll = new Poll();
            newPoll.Question = question;
            PollSystemEntities context = new PollSystemEntities();
            context.Polls.AddObject(newPoll);
            context.SaveChanges();

            if (!string.IsNullOrWhiteSpace(answer1))
                CreateAnswer(answer1, newPoll);
            if (!string.IsNullOrWhiteSpace(answer2))
                CreateAnswer(answer2, newPoll);
            if (!string.IsNullOrWhiteSpace(answer3))
                CreateAnswer(answer3, newPoll);
            if (!string.IsNullOrWhiteSpace(answer4))
                CreateAnswer(answer4, newPoll);
            if (!string.IsNullOrWhiteSpace(answer5))
                CreateAnswer(answer5, newPoll);
            if (!string.IsNullOrWhiteSpace(answer6))
                CreateAnswer(answer6, newPoll);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Polls EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPolls(Poll poll)
 {
     base.AddObject("Polls", poll);
 }
 /// <summary>
 /// Create a new Poll object.
 /// </summary>
 /// <param name="pollID">Initial value of the PollID property.</param>
 /// <param name="question">Initial value of the Question property.</param>
 public static Poll CreatePoll(global::System.Int32 pollID, global::System.String question)
 {
     Poll poll = new Poll();
     poll.PollID = pollID;
     poll.Question = question;
     return poll;
 }
Example #4
0
 private static void CreateAnswer(string answerText, Poll newPoll)
 {
     using (PollSystemEntities context = new PollSystemEntities())
     {
         if (answerText.Length > 255)
         {
             // Special case: long text should be inserted directly
             string cmd = String.Format("INSERT INTO PollAnswers(Answer, Votes, PollID) VALUES ('{0}', {1}, {2})", answerText, 0, newPoll.PollID);
             context.ExecuteStoreCommand(cmd);
         }
         else
         {
             PollAnswer answer = new PollAnswer();
             answer.Answer = answerText;
             answer.PollID = newPoll.PollID;
             answer.Votes = 0;
             context.PollAnswers.AddObject(answer);
         }
         context.SaveChanges();
     }
 }