public IActionResult GetOpenLessonsChartData()
        {
            LessonBusiness     lessonManager      = new LessonBusiness(DbContext);
            UserSessionContext userSessionContext = new UserSessionContext(this.HttpContext);

            //Filter by lessons user owns.  For Admin, show all.
            var filter = new LessonFilters {
                ShowOnlyOwnedLessons = true
            };

            int unused      = 0;
            var userLessons = lessonManager.GetLessonsPaged(userSessionContext.CurrentUser, filter, false, 0, 0, out unused)
                              .Where(x => x.StatusId != (int)Enumerations.LessonStatus.MIGRATION && x.StatusId != (int)Enumerations.LessonStatus.Closed).ToList();

            var data = from l in userLessons
                       group l by l.Status into lessonsByStatus
                       select new
            {
                Label    = lessonsByStatus.Key.Name,
                Percent  = Math.Round((((double)lessonsByStatus.Count()) / userLessons.Count() * 100), 1),
                Count    = lessonsByStatus.Count(),
                StatusId = lessonsByStatus.Key.Id,
                Sort     = lessonsByStatus.Key.SortOrder
            };

            return(Json(data.OrderBy(x => x.Sort)));
        }
        public IActionResult GetClosedLessonsChartData(int year, bool isValidSelected)
        {
            LessonBusiness     lessonManager      = new LessonBusiness(DbContext);
            UserSessionContext userSessionContext = new UserSessionContext(this.HttpContext);
            ApplicationContext appContext         = new ApplicationContext(this.Cache);

            int unused      = 0;
            var userLessons = lessonManager.GetLessonsPaged(userSessionContext.CurrentUser,
                                                            new LessonFilters
            {
                //Status = (int)Enumerations.LessonStatus.Closed
                SelectedStatus       = new List <int>(new int[] { (int)Enumerations.LessonStatus.Closed }),
                ShowOnlyOwnedLessons = userSessionContext.CurrentUser.RoleId != (int)Enumerations.Role.Administrator
            },
                                                            false, true, 0, 0, out unused);

            //Meaning "Pre-2010" was selected from the list, gatehr all lessons closed previous to Jan 1 2010
            if (year == 0)
            {
                userLessons = userLessons.Where(x => x.ClosedDate.HasValue && x.ClosedDate.Value.Year < 2010).ToList();
            }
            else
            {
                //Another valid year was selected
                userLessons = userLessons.Where(x => x.ClosedDate.HasValue && x.ClosedDate.Value.Year == year).ToList();
            }

            List <ReferenceValue> distinctLessonTypes = new List <ReferenceValue>();

            if (isValidSelected)
            {
                distinctLessonTypes = appContext.LessonTypesValid.Where(x => x.Enabled || userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator).Distinct().OrderBy(x => x.SortOrder).ToList();
            }
            else
            {
                distinctLessonTypes = appContext.LessonTypesInvalid.Where(x => x.Enabled || userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator).Distinct().OrderBy(x => x.SortOrder).ToList();
            }

            List <ClosedLessonType> closedLessonTypeData = new List <ClosedLessonType>();

            //Create a detail for each distinct lesson type
            foreach (var lessonType in distinctLessonTypes)
            {
                ClosedLessonType closedLessonType = new ClosedLessonType();
                closedLessonType.LessonTypeId   = lessonType.Id;
                closedLessonType.LessonTypeName = lessonType.Name;

                //Get the data for each Month
                for (int i = 1; i <= 12; i++)
                {
                    ClosedLessonTypeDetail month = new ClosedLessonTypeDetail
                    {
                        Count = userLessons.Where(x =>
                                                  (isValidSelected ? x.LessonTypeValidId : x.LessonTypeInvalidId) == lessonType.Id &&
                                                  x.ClosedDate.Value.Month == i).Count()
                    };

                    closedLessonType.Detail.Add(month);
                }

                closedLessonTypeData.Add(closedLessonType);
            }

            return(Json(closedLessonTypeData));
        }
예제 #3
0
        public IActionResult Index(Enumerations.PageAction pageAction, int?lessonId)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            var            lessonModel     = new LessonViewModel(this.HttpContext);
            LessonBusiness businessManager = new LessonBusiness(DbContext);

            SearchViewModel userSearch = new SearchViewModel();

            //Set Lesson List search based on page action
            switch (pageAction)
            {
            case Enumerations.PageAction.Submit:
                //Show only current user's draft lessons
                userSearch = new SearchViewModel {
                    OwnerSid = userContext.CurrentUser.Sid, Status = (int?)Enumerations.LessonStatus.Draft
                };
                break;

            case Enumerations.PageAction.Edit:
                //Show only editable lessons
                userSearch = new SearchViewModel {
                    ShowEditableOnly = true
                };
                break;

            case Enumerations.PageAction.Search:
                //Show the last search
                userSearch = userContext.LastSearch;
                break;

            case Enumerations.PageAction.MyLessons:
                //Show all owned lessons (or filtered lessons of comming from dashboard)
                userSearch = (SearchViewModel)TempData["MyLessonModel"] ?? new SearchViewModel {
                    ShowOnlyOwnedLessons = true
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("pageAction");
            }

            if (TempData.ContainsKey("Lesson"))
            {
                //Existing lesson (Edit Validation)
                lessonModel = (LessonViewModel)TempData["Lesson"];
            }
            else if (lessonId.HasValue &&
                     (pageAction == Enumerations.PageAction.Edit || pageAction == Enumerations.PageAction.Submit))
            {
                //Existing Lesson (Edit Existing)
                var lesson = businessManager.GetLessonById(lessonId.Value);
                lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);

                if (!Utils.IsLessonVisible(lessonModel, userContext.CurrentUser))
                {
                    return(RedirectToAction("Search"));
                }
            }
            else
            {
                if (pageAction != Enumerations.PageAction.Edit)
                {
                    if (lessonId.HasValue)
                    {
                        //Submit with "Save Changes", leave on submit tab with the recently added lesson
                        var lesson = businessManager.GetLessonById(lessonId.Value);
                        lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);
                    }
                    else
                    {
                        //New Lesson (Submit)
                        lessonModel = userContext.DraftDefaults;
                    }
                }
                else
                {
                    int unused = 0;
                    //Edit / Review, set to first lesson in search list
                    var lesson = businessManager.GetLessonsPaged(userContext.CurrentUser, userSearch, false, true, 0, 1, out unused).FirstOrDefault();
                    lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);
                    if (lesson != null)
                    {
                        lessonId = lesson.Id;
                    }
                    else
                    {
                        ViewBag.NothingToEdit = true;
                    }
                }
            }

            lessonModel.ReturnToAction = pageAction;

            var submittedUsers = businessManager.GetSubmittedByUsers();

            ViewBag.SubmittedByUsers = submittedUsers;

            userContext.LastSystemSearch = userSearch;

            LessonIndexViewModel model = new LessonIndexViewModel(this.HttpContext)
            {
                PageAction  = pageAction,
                LessonId    = lessonId,
                Lesson      = lessonModel,
                SearchModel = userSearch
            };

            return(View("Index", model));
        }
예제 #4
0
        public IActionResult GetLessonList(DataTableParametersViewData gridData)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            //Ensure iDisplayLength never causes a divide by zero exception
            gridData.iDisplayLength = (gridData.iDisplayLength == 0) ? 10 : gridData.iDisplayLength;

            int pageIndex = (gridData.iDisplayStart / gridData.iDisplayLength) + 1;

            pageIndex = pageIndex <= 0 ? 0 : pageIndex - 1;
            var pageSize   = gridData.iDisplayLength;
            int totalCount = 0;

            LessonBusiness lessonBusinessManager = new LessonBusiness(DbContext);

            string gridMessage = "";

            switch (gridData.NavigationPage)
            {
            case Enumerations.NavigationPage.Review:
            case Enumerations.NavigationPage.Edit:
            case Enumerations.NavigationPage.Validate:
                gridMessage = "Lessons Requiring Action";
                break;

            case Enumerations.NavigationPage.MyLessons:
                gridMessage = "My Lessons";
                //if (gridData.SearchModel.Status.HasValue)//TODO: Add logic for multiple options
                //{
                //    gridMessage = "My " + Utility.StringValue((Enumerations.LessonStatus)gridData.SearchModel.Status.Value) + " Lessons";
                //}
                if (gridData.SearchModel.SelectedStatus != null && gridData.SearchModel.SelectedStatus.Count > 0)   //TODO: Add logic for multiple options
                {
                    string StatusList = "";
                    foreach (int StatusID in gridData.SearchModel.SelectedStatus)
                    {
                        StatusList += Utility.StringValue((Enumerations.LessonStatus)StatusID);
                        StatusList += ", ";
                    }
                    gridMessage = "My " + StatusList + " Lessons";
                }
                break;

            case Enumerations.NavigationPage.Search:
                gridMessage = "Filtered Search Results";
                break;

            case Enumerations.NavigationPage.Submit:
                gridMessage = "My Draft Lessons";
                break;
            }

            List <Lesson> lessons = null;

            if (!gridData.SearchModel.Blank)
            {
                List <SortColumn> sortColumns = null;

                if (gridData.iSortingCols > 0)
                {
                    sortColumns = new List <SortColumn>();

                    if (gridData.iSortingCols > 5)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_5, Direction = gridData.sSortDir_5 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 6
                        });
                    }

                    if (gridData.iSortingCols > 4)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_4, Direction = gridData.sSortDir_4 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 5
                        });
                    }

                    if (gridData.iSortingCols > 3)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_3, Direction = gridData.sSortDir_3 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 4
                        });
                    }

                    if (gridData.iSortingCols > 2)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_2, Direction = gridData.sSortDir_2 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 3
                        });
                    }

                    if (gridData.iSortingCols > 1)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_1, Direction = gridData.sSortDir_1 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 2
                        });
                    }

                    sortColumns.Add(new SortColumn {
                        Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_0, Direction = gridData.sSortDir_0 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 1
                    });
                }

                lessons = lessonBusinessManager.GetLessonsPaged(sortColumns, userContext.CurrentUser, gridData.SearchModel, false, true, pageIndex, pageSize, out totalCount);
            }

            userContext.LastSearchResults = lessons;

            List <object> result = new List <object>();

            if (lessons != null)
            {
                foreach (var lesson in lessons)
                {
                    Dictionary <string, string> lessonData = new Dictionary <string, string>();
                    lessonData.Add("Enabled", lesson.Enabled.ToString());
                    lessonData.Add("Selected", false.ToString());
                    lessonData.Add("Id", lesson.Id.ToString());
                    lessonData.Add("Status", lesson.Status.Name + (lesson.Enabled == true ? "" : " (Deleted)"));
                    lessonData.Add("Title", HttpUtility.HtmlEncode(lesson.Title));
                    lessonData.Add("Discipline", lesson.Discipline == null ? "" : HttpUtility.HtmlEncode(lesson.Discipline.Name));
                    lessonData.Add("SubmitDate", lesson.SubmittedDate.HasValue ? lesson.SubmittedDate.Value.ToShortDateString() : "");
                    lessonData.Add("Contact", HttpUtility.HtmlEncode(Utility.ContactToDisplayString(lesson.ContactLastName, lesson.ContactFirstName)));
                    string buttonHtml = Utils.RenderPartialViewToString(this, "GridButton", LessonViewModel.ToViewModel(this.HttpContext, lesson));
                    lessonData.Add("Actions", buttonHtml);
                    lessonData.Add("LessonId", lesson.Id.ToString());
                    lessonData.Add("StatusId", lesson.StatusId.ToString());

                    var rawLessonData = (from l in lessonData
                                         select l.Value).ToArray();

                    result.Add(rawLessonData);
                }
            }

            return(Json(
                       new
            {
                eEcho = gridData.sEcho,
                iTotalRecords = totalCount,
                iTotalDisplayRecords = totalCount,
                aaData = result,
                gridMessage = gridMessage
            }));
        }