示例#1
0
        public async Task <IActionResult> Index(IndexFlightViewModel model)
        {
            model.Pager             = new PagerViewModel();
            model.Pager.CurrentPage = model.Pager.CurrentPage <= 0 ? 1 : model.Pager.CurrentPage;

            List <FlightViewModel> items = await _context.Flights.Skip((model.Pager.CurrentPage - 1) *PageSize).Take(PageSize).Select(c => new FlightViewModel()
            {
                Id              = c.Id,
                LocationFromId  = c.LocationFromId,
                LocationToId    = c.LocationToId,
                TakeOffDateTime = c.TakeOffDateTime,
                LandingDateTime = c.LandingDateTime,
                PlaneId         = c.PlaneId
            }).ToListAsync();

            model.Items            = items;
            model.Pager.PagesCount = (int)Math.Ceiling(_context.Flights.Count() / (double)PageSize);

            //////////////////// check for logged in employee -> admin
            byte[] empIdBytes = new byte[200];
            if (HttpContext.Session.TryGetValue("empId", out empIdBytes))
            {
                int employeeId = int.Parse(Encoding.UTF8.GetString(empIdBytes));
                if (employeeId == 1)
                {
                    Employee employee = _context.Employees.Find(employeeId);
                    ViewData["username"]   = employee.Username;
                    ViewData["isLoggedIn"] = true;
                    ViewData["isAdmin"]    = true;

                    return(RedirectToAction(nameof(AdminIndex)));
                }
                else if (employeeId != 1 && employeeId > 0)
                {
                    Employee employee = _context.Employees.Find(employeeId);;
                    ViewData["username"]   = employee.Username;
                    ViewData["isLoggedIn"] = true;
                    ViewData["isAdmin"]    = false;

                    return(View(model));
                }
                else
                {
                    ViewData["isLoggedIn"] = false;
                    ViewData["isAdmin"]    = false;

                    return(View(model));
                }
            }
            else
            {
                ViewData["isLoggedIn"] = false;
                ViewData["isAdmin"]    = false;

                return(View(model));
            }
            ///////////////////////////////////////////////////////////////
        }
        public ActionResult Filter(IndexFlightViewModel model, string returnUrl)
        {
            //Get value filter when push over buton Search
            Session["FlightSearchFilter"] = model.Filter.Flight;

            ViewBag.Filtro = true;

            return(RedirectToAction("Index"));
        }
        // GET: Flight
        public ActionResult Index()
        {
            IndexFlightViewModel viewModel = new IndexFlightViewModel();

            return(View(viewModel));
        }