public ActionResult ShowLessonList(LessonOverviewQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            if (viewModel.KeyID != null)
            {
                viewModel.LessonID = viewModel.DecryptKeyValue();
            }

            var items = viewModel.InquireLesson(models);

            return(View("~/Views/LessonConsole/Module/LessonList.cshtml", items));
        }
        public ActionResult ProcessLesson(LessonOverviewQueryViewModel viewModel)
        {
            if (viewModel.KeyID != null)
            {
                viewModel.LessonID = viewModel.DecryptKeyValue();
            }

            var item = models.GetTable <LessonTime>().Where(c => c.LessonID == viewModel.LessonID).FirstOrDefault();

            if (item == null)
            {
                return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "資料錯誤!!"));
            }

            return(View("~/Views/LessonConsole/Module/ProcessLesson.cshtml", item));
        }
Beispiel #3
0
        public static IQueryable <LessonTime> InquireLesson(this LessonOverviewQueryViewModel viewModel, GenericManager <BFDataContext> models, bool exclusiveCoachOrBranch = false)

        {
            IQueryable <LessonTime> items = models.GetTable <LessonTime>();

            if (viewModel.Year.HasValue && viewModel.Month.HasValue)
            {
                viewModel.DateFrom = new DateTime(viewModel.Year.Value, viewModel.Month.Value, 1);
                viewModel.DateTo   = viewModel.DateFrom.Value.AddMonths(1);
            }

            if (viewModel.LessonID.HasValue)
            {
                items = items.Where(t => t.LessonID == viewModel.LessonID);
            }

            if (viewModel.CoachID.HasValue)
            {
                items = items.Where(c => c.AttendingCoach == viewModel.CoachID);
            }

            if (exclusiveCoachOrBranch == false || !viewModel.CoachID.HasValue)
            {
                if (viewModel.BranchID.HasValue)
                {
                    if (viewModel.ByManager == true)
                    {
                        var allCoach = models.GetTable <CoachWorkplace>().Where(w => w.BranchID == viewModel.BranchID)
                                       .Where(w => !models.GetTable <CoachWorkplace>().Where(c => c.CoachID == w.CoachID)
                                              .Any(c => c.BranchID != viewModel.BranchID))
                                       .Select(w => w.CoachID);
                        items = items.Where(c => allCoach.Any(w => w == c.AttendingCoach));
                    }
                    else
                    {
                        items = items.Where(c => c.BranchID == viewModel.BranchID);
                    }
                }
            }

            if (viewModel.DateFrom.HasValue)
            {
                items = items.Where(c => c.ClassTime >= viewModel.DateFrom);
            }

            if (viewModel.DateTo.HasValue)
            {
                items = items.Where(c => c.ClassTime < viewModel.DateTo);
            }

            if (viewModel.CoachAttended == true)
            {
                items = items.Where(l => l.LessonAttendance != null);
            }
            else if (viewModel.CoachAttended == false)
            {
                items = items.Where(t => t.LessonAttendance == null);
            }

            if (viewModel.LearnerCommitted == true)
            {
                items = items.Where(t => t.LessonPlan.CommitAttendance.HasValue);
            }
            else if (viewModel.LearnerCommitted == false)
            {
                items = items.Where(t => !t.LessonPlan.CommitAttendance.HasValue);
            }

            if (viewModel.LessonType.HasValue)
            {
                items = items.ByLessonQueryType(viewModel.LessonType);
            }

            if (viewModel.CombinedStatus != null && viewModel.CombinedStatus.Length > 0)
            {
                var tuition = models.GetTable <V_Tuition>().Where(v => viewModel.CombinedStatus.Contains((Naming.LessonPriceStatus)v.PriceStatus));
                items = items.Join(tuition, l => l.LessonID, v => v.LessonID, (l, v) => l);
            }

            return(items);
        }
Beispiel #4
0
        public static IQueryable <LessonTime> InquireLesson <TEntity>(this LessonOverviewQueryViewModel viewModel, ModelSource <TEntity> models, bool exclusiveCoachOrBranch = false)
            where TEntity : class, new()
        {
            IQueryable <LessonTime> items = models.GetTable <LessonTime>();

            if (viewModel.Year.HasValue && viewModel.Month.HasValue)
            {
                viewModel.DateFrom = new DateTime(viewModel.Year.Value, viewModel.Month.Value, 1);
                viewModel.DateTo   = viewModel.DateFrom.Value.AddMonths(1);
            }

            if (viewModel.LessonID.HasValue)
            {
                items = items.Where(t => t.LessonID == viewModel.LessonID);
            }

            if (viewModel.CoachID.HasValue)
            {
                items = items.Where(c => c.AttendingCoach == viewModel.CoachID);
            }

            if (exclusiveCoachOrBranch == false || !viewModel.CoachID.HasValue)
            {
                if (viewModel.BranchID.HasValue)
                {
                    if (viewModel.ByManager == true)
                    {
                        var allCoach = models.GetTable <CoachWorkplace>().Where(w => w.BranchID == viewModel.BranchID)
                                       .Where(w => !models.GetTable <CoachWorkplace>().Where(c => c.CoachID == w.CoachID)
                                              .Any(c => c.BranchID != viewModel.BranchID))
                                       .Select(w => w.CoachID);
                        items = items.Where(c => allCoach.Any(w => w == c.AttendingCoach));
                    }
                    else
                    {
                        items = items.Where(c => c.BranchID == viewModel.BranchID);
                    }
                }
            }

            if (viewModel.DateFrom.HasValue)
            {
                items = items.Where(c => c.ClassTime >= viewModel.DateFrom);
            }

            if (viewModel.DateTo.HasValue)
            {
                items = items.Where(c => c.ClassTime < viewModel.DateTo);
            }

            if (viewModel.CoachAttended == true)
            {
                items = items.Where(l => l.LessonAttendance != null);
            }
            else if (viewModel.CoachAttended == false)
            {
                items = items.Where(t => t.LessonAttendance == null);
            }

            if (viewModel.LearnerCommitted == true)
            {
                items = items.Where(t => t.LessonPlan.CommitAttendance.HasValue);
            }
            else if (viewModel.LearnerCommitted == false)
            {
                items = items.Where(t => !t.LessonPlan.CommitAttendance.HasValue);
            }

            if (viewModel.LessonType.HasValue)
            {
                items = items.ByLessonQueryType(viewModel.LessonType);
            }

            return(items);
        }