/// <summary> /// Get all the questions for a test /// </summary> /// <param name="id">Id of the test to retrieve</param> /// <returns>returns all questions and choices for a given test</returns> public Test Get(int id = 1) { var response = new Test(); try { using (var context = new DbModel()) { response = context.Tests.AsNoTracking() .Where(x => x.Id == id) .Include("Questions") .Include("Questions.Choices") .FirstOrDefault(); if (response != null) { response.Questions = response.Questions.OrderBy(item => rnd.Next()).ToList(); foreach (var question in response.Questions) question.Choices = question.Choices.OrderBy(item => rnd.Next()).ToList(); } } } catch (Exception e) { logger.Error(e); } return response; }
public List<Question> Get() { var response = new List<Question>(); try { using (var context = new DbModel()) { context.Tests.Add( new Test { Name = "Rustici Software", Questions = new List<Question> { new Question { Detail = "What can you find in Rustici Software's office?", SingleAnswer = false, Choices = new List<Choice> { new Choice { Detail = "Dart Board", Answer = true}, new Choice { Detail = "Ping Pong Table", Answer = true}, new Choice { Detail = "Cubicles", Answer = false}, new Choice { Detail = "Laptops with dual monitors", Answer = true}, new Choice { Detail = "TPS reports, ummm yeah", Answer = false}, } }, new Question { Detail = "All of Rustici Software employees are expected to work no more than ____ hours per week.", SingleAnswer = true, Choices = new List<Choice> { new Choice { Detail = "80", Answer = false}, new Choice { Detail = "40", Answer = true}, new Choice { Detail = "50", Answer = false}, new Choice { Detail = "60", Answer = false}, } }, new Question { Detail = "The end users of Rustici Software's products number in the _________", SingleAnswer = true, Choices = new List<Choice> { new Choice { Detail = "Tens", Answer = false}, new Choice { Detail = "Hundreds", Answer = false}, new Choice { Detail = "Thousands", Answer = false}, new Choice { Detail = "Millions", Answer = true}, new Choice { Detail = "Billions", Answer = false}, } }, new Question { Detail = "Rustici Software is a (choose all that apply):", SingleAnswer = false, Choices = new List<Choice> { new Choice { Detail = "Great place to work", Answer = true}, new Choice { Detail = "Respected leader in its field", Answer = true}, new Choice { Detail = "Place where people don't matter, just results", Answer = false}, } }, new Question { Detail = "Tim likes to wear:", SingleAnswer = true, Choices = new List<Choice> { new Choice { Detail = "Capri pants", Answer = false}, new Choice { Detail = "Goth attire", Answer = false}, new Choice { Detail = "Sport coat", Answer = false}, new Choice { Detail = "T-shirt and shorts", Answer = true}, } } } } ); context.SaveChanges(); response = context.Questions.AsNoTracking().ToList(); } } catch (Exception e) { logger.Error(e); } return response; }