Beispiel #1
0
 public Homework Add(Homework homework)
 {
     using (var context = new HomeworksContext())
     {
         homework = context.Homeworks.Add(homework);
         context.SaveChanges();
     }
     return(homework);
 }
Beispiel #2
0
 public bool DeleteById(Guid id)
 {
     using (var context = new HomeworksContext())
     {
         Homework homework = context.Homeworks.Include("Exercises").FirstOrDefault(p => p.Id == id);
         if (homework == null)
         {
             return(false);
         }
         context.Homeworks.Remove(homework);
         context.SaveChanges();
         return(true);
     }
 }
Beispiel #3
0
        public bool Update(Guid id, Homework updatedHomework)
        {
            using (var context = new HomeworksContext())
            {
                Homework originalHomework = context.Homeworks.FirstOrDefault(p => p.Id == id);
                if (originalHomework == null)
                {
                    return(false);
                }
                originalHomework.Description = updatedHomework.Description;
                originalHomework.DueDate     = updatedHomework.DueDate;

                context.SaveChanges();
                return(true);
            }
        }
 public Exercise Add(Guid homeworkId, Exercise exercise)
 {
     using (var context = new HomeworksContext())
     {
         Homework homework = context.Homeworks.Include("Exercises").FirstOrDefault(h => h.Id == homeworkId);
         if (homework != null)
         {
             homework.Exercises.Add(exercise);
             context.SaveChanges();
             return(exercise);
         }
         else
         {
             return(null);
         }
     }
 }