Ejemplo n.º 1
0
        public ActionResult GetSquawksForAircraft(int id)
        {
            Aircraft aircraft = _dataService.GetAircraftById(id);

            if (aircraft == null)
            {
                throw new HttpException(404, "Aircraft Not Found");
            }

            List <Squawk> squawks = _dataService.GetSquawksByAircraftId(id);

            ProfileCommon profile = HttpContext.Profile as ProfileCommon;

            if (profile == null)
            {
                RedirectToAction("LogOn", "Account");
            }


            SquawksForAircraftViewModel viewModel = new SquawksForAircraftViewModel()
            {
                AircraftId         = id,
                RegistrationNumber = aircraft.RegistrationNumber,
                Name    = aircraft.Name,
                Squawks = squawks.ConvertToSquawkItemViewModel(),
            };

            bool isOwner = _dataService.IsAircraftOwner(profile.MemberId, id);

            if (isOwner || User.IsInRole(UserRoles.Admin.ToString()) || User.IsInRole(UserRoles.AircraftMaintenance.ToString()))
            {
                viewModel.CanResolveSquawks = true;
            }
            else
            {
                viewModel.CanResolveSquawks = false;
            }

            return(View(ViewNames.SquawksForAircraft, viewModel));
        }