public async Task <IActionResult> Index()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                var userName = HttpContext.User.Identity.Name;
                MemberSummaryViewModel vm = new MemberSummaryViewModel
                {
                    IncomingBookings      = await _mediator.Send(new GetIncomingBookingsQuery(userName)),
                    IncomingBookingsCount = await _mediator.Send(new GetIncomingBookingsCountQuery(userName)),
                    TotalBookingsCount    = await _mediator.Send(new GetTotalBookingsCountQuery(userName)),
                    NextFlights           = await _mediator.Send(new GetIncomingFlightsQuery()),
                    Logs = await _mediator.Send(new GetUserLogsQuery(userName))
                };
                if (User.IsInRole("Pilot"))
                {
                    vm.NextFlightsToDo = await _mediator.Send(new GetFlightsPerPilotQuery(userName, 3));

                    vm.TotalFlightsDoneCount = await _mediator.Send(new GetTotalFlightsCountQuery(userName));

                    vm.FlightsToDoCount = await _mediator.Send(new GetIncomingFlightsCountQuery(userName));
                }
                if (User.IsInRole("Director"))
                {
                    vm.TotalFlightsCount = await _mediator.Send(new GetTotalFlightsCountQuery());

                    vm.TotalIncomingFlightsCount = await _mediator.Send(new GetIncomingFlightsCountQuery());
                }

                return(View(vm));
            }
            return(View());
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(string name)
        {
            var search = string.IsNullOrWhiteSpace(name) ?
                         await _context.Members.Include(m => m.OwnedVehicles).ToListAsync()  :
                         await _context.Members.Include(m => m.OwnedVehicles).Where(m => (m.FirstName + " " + m.LastName).Contains(name)).ToListAsync();

            var models   = new List <MemberSummaryViewModel>();
            var vehicles = await _context.ParkedVehicles.ToListAsync();

            foreach (var member in search)
            {
                var model = new MemberSummaryViewModel
                {
                    Id        = member.MemberId,
                    FirstName = member.FirstName,
                    LastName  = member.LastName
                };
                model.Count = member.OwnedVehicles.Count;
                models.Add(model);
            }

            return(View(models));
        }