public void AddQuestion(Question question) { try { context.Questions.Add(question); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message + "\n"); } }
public void AddQuestions() { context.Questions.Add(new Question { Id = new Guid(), Title = "What's 2 x 2?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "8", isCorrect = false }, new Answer { id = new Guid(), Title = "6", isCorrect = false }, new Answer { id = new Guid(), Title = "4", isCorrect = true }, } }); context.Questions.Add(new Question { Id = new Guid(), Title = "When did World War 2 start?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "1940", isCorrect = false }, new Answer { id = new Guid(), Title = "1939", isCorrect = true }, new Answer { id = new Guid(), Title = "1938", isCorrect = false }, } }); context.Questions.Add(new Question { Id = new Guid(), Title = "How many times has Sweden won in the Eurovision song contest?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "9", isCorrect = false }, new Answer { id = new Guid(), Title = "6", isCorrect = true }, new Answer { id = new Guid(), Title = "8", isCorrect = false }, } }); context.Questions.Add(new Question { Id = new Guid(), Title = "What's the meaning of life?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "Dogs", isCorrect = false }, new Answer { id = new Guid(), Title = "Cats", isCorrect = false }, new Answer { id = new Guid(), Title = "42", isCorrect = true }, } }); context.Questions.Add(new Question { Id = new Guid(), Title = "How many frets does a regular acoustic guitar have?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "24", isCorrect = true }, new Answer { id = new Guid(), Title = "22", isCorrect = false }, new Answer { id = new Guid(), Title = "20", isCorrect = false }, } }); context.Questions.Add(new Question { Id = new Guid(), Title = "What's Emil's best Apex Legends rank?", Answers = new List <Answer> { new Answer { id = new Guid(), Title = "Top 200", isCorrect = false }, new Answer { id = new Guid(), Title = "Top 300", isCorrect = false }, new Answer { id = new Guid(), Title = "Top 400", isCorrect = true }, new Answer { id = new Guid(), Title = "Top 500", isCorrect = false }, new Answer { id = new Guid(), Title = "Top 600", isCorrect = false } } }); context.SaveChanges(); }