// GET: Admin/LessonPlans
        public async Task <IActionResult> Index()
        {
            List <ClassRoom> classRooms = new List <ClassRoom>();

            foreach (var classRoom in _context.ClassRoom)
            {
                classRooms.Add(classRoom);
            }
            ViewBag.ClassRoomsList = classRooms;

            await _context.LessonPlan.Include(x => x.Course).ToListAsync();

            await _context.LessonPlan.Include(x => x.ClassRoom).ToListAsync();

            List <List <List <LessonPlan> > > datas = new List <List <List <LessonPlan> > >();

            lessonListGenerator(datas);
            var model = new LessonPlanViewModel()
            {
                LessonsList = datas
            };

            //return View(_context.LessonPlan.OrderBy(a => a.startTime));
            return(View(model));


            //return View(await context.Teachers.OrderByDescending(x => x.Id).Include(x => x.Course).ToListAsync());
        }
예제 #2
0
        public async Task <IActionResult> EditLessonPlan(Guid?classId, DateTime?date)
        {
            var lessonPlan = await _unitOfWork.LessonPlans.GetOneAsync(x => x.IsActive && x.ClassId == classId && x.Date == date);

            var model = new LessonPlanViewModel();

            if (lessonPlan != null)
            {
                model = LessonPlan.Init(lessonPlan);
            }
            else
            {
                model.Date = date.Value;
            }
            var sundayDateOfWeek = model.Date.AddDays(7 - (int)model.Date.DayOfWeek);
            LessonPlanWeakly weeklyLessonPlan = await _unitOfWork.LessonPlanWeaklies.GetOneAsync(x => x.IsActive &&
                                                                                                 x.ClassId == classId &&
                                                                                                 x.WeekDateSunday == sundayDateOfWeek);

            if (weeklyLessonPlan != null)
            {
                model.WeeklyTheme        = weeklyLessonPlan.Theme;
                model.LessonPlanWeeklyId = weeklyLessonPlan.Id;
            }

            return(View(model));
        }
예제 #3
0
 public static LessonPlanWeakly Create(LessonPlanViewModel model, DateTime weekDaySunday, string userId)
 {
     return(new LessonPlanWeakly()
     {
         Theme = model.WeeklyTheme,
         ClassId = model.ClassId,
         OrgnizationId = new Guid("2675d289-f8cd-4596-ad75-dfa58ee817af"),
         WeekDateSunday = weekDaySunday,
         CreatedById = userId
     });
 }
예제 #4
0
 public static LessonPlan Create(LessonPlanViewModel model, string userId)
 {
     return(new LessonPlan()
     {
         Date = model.Date,
         Theme = model.Theme,
         Notes = model.Notes,
         CreatedById = userId,
         ClassId = model.ClassId,
         OrganizationId = new Guid("2675d289-f8cd-4596-ad75-dfa58ee817af"),
     });
 }
예제 #5
0
        public async Task <JsonResult> EditLessonPlan(LessonPlanViewModel model)
        {
            //Update weekly theme
            var sundayDateOfWeek = model.Date.AddDays(7 - (int)model.Date.DayOfWeek);
            LessonPlanWeakly weeklyLessonPlan = await _unitOfWork.LessonPlanWeaklies.GetOneAsync(x => x.IsActive && x.Id == model.LessonPlanWeeklyId);

            if (weeklyLessonPlan != null)
            {
                weeklyLessonPlan.Theme = model.WeeklyTheme;
                _unitOfWork.LessonPlanWeaklies.Update(weeklyLessonPlan);
            }
            else
            {
                if (String.IsNullOrEmpty(model.WeeklyTheme) == false)
                {
                    weeklyLessonPlan = LessonPlanWeakly.Create(model, sundayDateOfWeek, _userId);
                    await _unitOfWork.LessonPlanWeaklies.Insert(weeklyLessonPlan);
                }
            }
            //Update daily theme
            if (model.LessonPlanId == null)
            {
                if (String.IsNullOrEmpty(model.Theme) == false)
                {
                    var lessonPlan = LessonPlan.Create(model, _userId);
                    await _unitOfWork.LessonPlans.Insert(lessonPlan);
                }
            }
            else
            {
                var lessonPlan = await _unitOfWork.LessonPlans.GetOneAsync(x => x.IsActive && x.Id == model.LessonPlanId);

                lessonPlan.Update(model);
                _unitOfWork.LessonPlans.Update(lessonPlan);
            }
            var result = await _unitOfWork.SaveAsync();

            if (result.Succeeded)
            {
                return(Json(new JsonMessage {
                    Color = "#ff6849", Message = "Lesson plan saved", Header = "Success", Icon = "success", AdditionalData = model
                }));
            }
            return(Json(new JsonMessage {
                Color = "#ff6849", Message = "Error", Header = "Success", Icon = "error", AdditionalData = model
            }));
        }
예제 #6
0
 public void Update(LessonPlanViewModel model)
 {
     Theme = model.Theme;
     Notes = model.Notes;
 }