public void SeedDatabase(bool force, List <Question> list)
 {
     using (var context = new MillionaireContext(list))
     {
         context.Database.Initialize(force);
     }
 }
 public void SaveChanges()
 {
     using (var context = new MillionaireContext())
     {
         context.SaveChanges();
     }
 }
 public void Delete(StatisticsEntry entry)
 {
     using (var context = new MillionaireContext())
     {
         context.Entry(entry).State = EntityState.Deleted;
     }
 }
 public StatisticsEntry GetById(int id)
 {
     using (var context = new MillionaireContext())
     {
         return(context.Set <StatisticsEntry>().Where(s => s.QuestionID == id).FirstOrDefault());
     }
 }
 public IList <StatisticsEntry> GetAll()
 {
     using (var context = new MillionaireContext())
     {
         return(context.Set <StatisticsEntry>().ToList());
     }
 }
Ejemplo n.º 6
0
 public void Delete(User user)
 {
     using (var context = new MillionaireContext())
     {
         context.Entry(user).State = EntityState.Deleted;
     }
 }
Ejemplo n.º 7
0
 public User GetById(int id)
 {
     using (var context = new MillionaireContext())
     {
         return(context.Set <User>().Where(u => u.UserID == id).FirstOrDefault());
     }
 }
Ejemplo n.º 8
0
 public IList <User> GetAll()
 {
     using (var context = new MillionaireContext())
     {
         return(context.Set <User>().ToList());
     }
 }
 public StatisticsEntry GetByQuestion(Question question)
 {
     using (var context = new MillionaireContext())
     {
         if (context.Statistics.Any(s => s.QuestionID == question.QuestionID))
         {
             return(context.Statistics.Where(s => s.Question.QuestionID == question.QuestionID)
                    .Include(s => s.Question.Answers).FirstOrDefault());
         }
         else
         {
             return(null);
         }
     }
 }
 public void Update(StatisticsEntry entry)
 {
     using (var context = new MillionaireContext())
     {
         var question = context.Questions.Where(q => q.QuestionID == entry.QuestionID)
                        .Include(q => q.Answers).FirstOrDefault();
         int i = 0;
         foreach (var child in question.Answers)
         {
             context.Entry(child).Entity.TimesSelected = entry.Question.Answers[i++].TimesSelected;
             context.Entry(child).State = EntityState.Modified;
         }
         context.SaveChanges();
     }
 }