Exemplo n.º 1
0
        public async Task <IActionResult> Types(string search, int page = 1)
        {
            PageTitle = "School Types";

            var filter = new BaseFilter(page)
            {
                Search = search
            };

            var typeList = await _schoolService.GetPaginatedTypeListAsync(filter);

            PaginateViewModel paginateModel = new PaginateViewModel()
            {
                ItemCount    = typeList.Count,
                CurrentPage  = page,
                ItemsPerPage = filter.Take.Value
            };

            if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            TypeListViewModel viewModel = new TypeListViewModel()
            {
                SchoolTypes   = typeList.Data.ToList(),
                PaginateModel = paginateModel,
            };

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Types(int page = 1)
        {
            PageTitle = "School Types";

            int take = 15;
            int skip = take * (page - 1);

            var typeList = await _schoolService.GetPaginatedTypeListAsync(skip, take);

            PaginateViewModel paginateModel = new PaginateViewModel()
            {
                ItemCount    = typeList.Count,
                CurrentPage  = page,
                ItemsPerPage = take
            };

            if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            TypeListViewModel viewModel = new TypeListViewModel()
            {
                SchoolTypes   = typeList.Data.ToList(),
                PaginateModel = paginateModel,
            };

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditType(TypeListViewModel model)
        {
            try
            {
                await _schoolService.UpdateTypeAsync(model.Type);

                ShowAlertSuccess($"School Type '{model.Type.Name}' updated");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to edit School Type: ", gex);
            }
            return(RedirectToAction("Types"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddType(TypeListViewModel model)
        {
            try
            {
                await _schoolService.AddSchoolType(model.Type.Name);

                ShowAlertSuccess($"Added School Type '{model.Type.Name}'");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to add School Type: ", gex);
            }
            return(RedirectToAction("Types"));
        }
Exemplo n.º 5
0
        public ActionResult Read(TypeListViewModel viewModel)
        {
            questStatus        status             = null;
            UserMessageModeler userMessageModeler = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                userMessageModeler = new UserMessageModeler(status);
                return(Json(userMessageModeler, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                userMessageModeler = new UserMessageModeler(status);
                return(Json(userMessageModeler, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            List <OptionValuePair> typeListOptionList = null;
            TypeListModeler        typeListModeler    = new TypeListModeler(this.Request, this.UserSession);

            status = typeListModeler.Read(viewModel, out typeListOptionList);
            if (!questStatusDef.IsSuccess(status))
            {
                userMessageModeler = new UserMessageModeler(status);
                return(Json(userMessageModeler, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            return(Json(typeListOptionList, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/
        public questStatus Read(TypeListViewModel typeListViewModel, out List <OptionValuePair> typeListOptionList)
        {
            // Initialize
            questStatus status = null;

            typeListOptionList = null;


            // Get typeList options
            TypeListId typeListId = new TypeListId(typeListViewModel.Id);
            List <TypeListArgument> typeListArgumentList = null;    // TODO
            TypeListMgr             typeListMgr          = new TypeListMgr(this.UserSession);

            status = typeListMgr.GetTypeListOptions(typeListId, typeListArgumentList, out typeListOptionList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }