Ejemplo n.º 1
0
 public List <LessonViewModel> Read(LessonBindingModel model)
 {
     if (model == null)
     {
         return(_lessonStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <LessonViewModel> {
             _lessonStorage.GetElement(model)
         });
     }
     return(_lessonStorage.GetFilteredList(model));
 }
        public List <LessonViewModel> GetFilteredList(LessonBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new SchoolDataBase())
            {
                return(context.Lessons
                       .Include(rec => rec.Employee)
                       .ThenInclude(rec => rec.User)
                       .Where(rec => rec.LessonName.Contains(model.LessonName))
                       .Select(CreateViewModel)
                       .ToList());
            }
        }
        public LessonViewModel GetElement(LessonBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new SchoolDataBase())
            {
                var lesson = context.Lessons
                             .Include(rec => rec.Employee)
                             .ThenInclude(rec => rec.User)
                             .FirstOrDefault(rec => rec.LessonName == model.LessonName ||
                                             rec.Id == model.Id);

                return(lesson != null?CreateViewModel(lesson) : null);
            }
        }