Beispiel #1
0
        public IActionResult Index(AllDataSearchModel filter, string?burialId, int pageNum = 1)
        {
            var filterLogic = new FilterLogic(_context);

            var queryModel = filterLogic.GetMummies(filter);
            int pageSize   = 120;

            //pagination

            return(View(new AllDataViewModel
            {
                AllData = (queryModel
                           .Skip((pageNum - 1) * pageSize)
                           .Take(pageSize)
                           .ToList()),

                PageNumberingInfo = new PageNumberingInfo
                {
                    NumItemsPerPage = pageSize,
                    CurrentPage = pageNum,
                    TotalNumItems = (burialId == null ? queryModel.Count() :
                                     queryModel.Where(x => x.BurialId == burialId).Count())
                },

                UrlInfo = Request.QueryString.Value
            }));
        }
        // GET: MasterBurial2

        public async Task <IActionResult> Index(Filter filter, int?burialId, int pageNum = 1)
        {
            //creates a list of Carbons with Burial IDs (so we can link them in the view)
            ViewBag.CarbonBurialList = _context.Carbon2
                                       .Where(c => c.BurialId != null)
                                       .ToList();

            ViewBag.SampleBurialList = _context.Samples2
                                       .Where(c => c.BurialId != null)
                                       .ToList();


            ViewBag.PhotoBurialList = _context.Photos
                                      .Where(p => p.Burial != null)
                                      .ToList();

            //ViewBag.Sample = _context.Samples2
            //    .Where(c => c.BurialId != null)
            //    .ToList();

            //variable of type filterLogic
            var filterLogic = new FilterLogic(_context);

            //queryModel that receives the return from the GetMummies method
            var queryModel = filterLogic.GetMummies(filter);

            //Page size upped in order for the jQuery table to function properly
            int pageSize = 10000;

            int skip = 0;

            //Used for asp.net pagination
            if (pageNum - 1 < 0)
            {
                skip = 0;
            }
            else
            {
                skip = (pageNum - 1) * pageSize;
            }

            //ViewBag of the different people that have Authorization to Edit and Delete
            ViewBag.AdminList = _context.AspNetUsers
                                .Where(b => b.isAdmin == true)
                                .ToList();


            ViewBag.ResearchList = _context.AspNetUsers
                                   .Where(c => c.isResearcher == true)
                                   .ToList();

            ViewBag.CurrentUser = _context.AspNetUsers
                                  .Where(c => c.UserName == User.Identity.Name);

            //check to see if user is an admin
            var isAdmin = _context.AspNetUsers
                          .Where(c => c.UserName == User.Identity.Name);

            foreach (var thing in isAdmin)
            {
                if (thing.isAdmin == true)
                {
                    ViewData["isAdmin"] = true;
                }
            }

            //check to see if the user is a researcher
            var isResearcher = _context.AspNetUsers
                               .Where(c => c.UserName == User.Identity.Name);

            foreach (var thing in isResearcher)
            {
                if (thing.isResearcher == true)
                {
                    ViewData["isResearcher"] = true;
                }
            }



            //int b = 0;
            //foreach (var item in (_context.AspNetUsers.Where(c => c.isAdmin == true).ToList()))
            //{
            //    ViewData[$"UserName{b}"] = $"{item.UserName}";
            //    b = b + 1;
            //}



            return(View(new PaginationViewModel
            {
                //Carbons = ((IQueryable<Carbon2>)_context.Carbon2.Include(c => c.Burial).ToListAsync()),

                //returning aspects of the ViewModel to be used in the view
                Burials = (queryModel
                           .Skip(skip)
                           .Take(pageSize)
                           .ToList()),

                PageNumberingInfo = new PageNumberingInfo
                {
                    NumItemsPerPage = pageSize,
                    CurrentPage = pageNum,

                    TotalNumItems = (burialId == null ? queryModel.Count() :
                                     queryModel.Where(x => x.BurialId == burialId).Count())
                },

                UrlInfo = Request.QueryString.Value
            }));
        }