Beispiel #1
0
        public override HttpHandlerResult Get()
        {
            var vm = new ApplicationIndexVM(this);

            vm.Build();

            return(Response.View("Applications\\Index.html", vm));
        }
        // get application list for the index page
        public ApplicationIndexVM GetApplicationList(string sortOrder, string currentFilter, string searchString, int?page)
        {
            try
            {
                // get the current logged in user's id
                var currentUserId = HttpContext.Current.User.Identity.GetUserId();

                IEnumerable <ApplicationListVM> applicationList = null;

                if (HttpContext.Current.User.IsInRole(Key.ROLE_ADMIN) || HttpContext.Current.User.IsInRole(Key.ROLE_STAFF))
                {
                    // if user is internal
                    applicationList = _context.Application
                                      .Select(c => new ApplicationListVM
                    {
                        ApplicationName = c.ApplicationName,
                        ReferenceID     = c.ReferenceID,
                        Description     = c.Description,
                        URL             = c.URL,
                        StatusName      = c.Status.StatusName,
                        ClientName      = c.Client.ClientName,
                    });
                }
                else if (HttpContext.Current.User.IsInRole(Key.ROLE_CLIENT))
                {
                    // if user is external admin
                    var getClientId = _context.UserDetail.Where(u => u.UserID == currentUserId).Select(c => c.Client.ClientName).FirstOrDefault();

                    applicationList = _context.Application
                                      .Where(c => c.Client.ClientName == getClientId)
                                      .Select(c => new ApplicationListVM
                    {
                        ApplicationName = c.ApplicationName,
                        ReferenceID     = c.ReferenceID,
                        Description     = c.Description,
                        URL             = c.URL,
                        StatusName      = c.Status.StatusName,
                        ClientName      = c.Client.ClientName,
                    });
                }
                else
                {
                    // if user is external user
                    applicationList = _context.UserDetail
                                      .Where(c => c.UserID == currentUserId).FirstOrDefault().Applications
                                      .Select(c => new ApplicationListVM
                    {
                        ApplicationName = c.ApplicationName,
                        ReferenceID     = c.ReferenceID,
                        Description     = c.Description,
                        URL             = c.URL,
                        StatusName      = c.Status.StatusName,
                        ClientName      = c.Client.ClientName,
                    });
                }

                int pageNumber      = (page ?? 1);
                int defaultPageSize = ConstantsRepo.PAGE_SIZE;
                page = searchString == null ? page : 1;
                int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
                searchString = searchString ?? currentFilter;
                var sorted               = Sort(applicationList, sortOrder, searchString);
                int totalNumOfApps       = sorted.Count();
                ApplicationIndexVM model = new ApplicationIndexVM
                {
                    Applications    = sorted.ToPagedList(pageNumber, ConstantsRepo.PAGE_SIZE),
                    CurrentFilter   = searchString,
                    TotalItemCount  = totalNumOfApps,
                    ItemStart       = currentPageIndex * defaultPageSize + 1,
                    ItemEnd         = totalNumOfApps - (defaultPageSize * currentPageIndex) >= defaultPageSize ? defaultPageSize * (currentPageIndex + 1) : totalNumOfApps,
                    CurrentSort     = sortOrder ?? ConstantsRepo.SORT_APP_BY_NAME_DESC,
                    ApplicationSort = sortOrder == ConstantsRepo.SORT_APP_BY_NAME_DESC ? ConstantsRepo.SORT_APP_BY_NAME_ASCE : ConstantsRepo.SORT_APP_BY_NAME_DESC,
                    StatusSort      = sortOrder == ConstantsRepo.SORT_STATUS_BY_NAME_DESC ? ConstantsRepo.SORT_STATUS_BY_NAME_ASCE : ConstantsRepo.SORT_STATUS_BY_NAME_DESC,
                    ClientSort      = sortOrder == ConstantsRepo.SORT_APP_BY_CLIENT_DESC ? ConstantsRepo.SORT_APP_BY_CLIENT_ASCE : ConstantsRepo.SORT_APP_BY_CLIENT_DESC,
                    DescriptionSort = sortOrder == ConstantsRepo.SORT_APP_BY_DESCRIPTION_DESC ? ConstantsRepo.SORT_APP_BY_DESCRIPTION_ASCE : ConstantsRepo.SORT_APP_BY_DESCRIPTION_DESC,
                    URLSort         = sortOrder == ConstantsRepo.SORT_APP_BY_URL_DESC ? ConstantsRepo.SORT_APP_BY_URL_ASCE : ConstantsRepo.SORT_APP_BY_URL_DESC,
                };
                return(model);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ApplicationIndexVM model = _aRepo.GetApplicationList(sortOrder, currentFilter, searchString, page);

            return(View(model));
        }