Exemplo n.º 1
0
        public ViewResult ListOwners(int?id)
        {
            List <Aircraft> aircraft = new List <Aircraft>();

            if (id == null)
            {
                aircraft = _dataService.GetAllAircraftWithOwners();
            }
            else
            {
                aircraft.Add(_dataService.GetAircraftById((int)id));
            }

            List <AircraftOwnersListViewModel> viewModel = new List <AircraftOwnersListViewModel>();

            foreach (var ac in aircraft)
            {
                AircraftOwnersListViewModel vmItem = new AircraftOwnersListViewModel();
                vmItem.AircraftId         = ac.Id;
                vmItem.RegistrationNumber = ac.RegistrationNumber;
                foreach (var owner in ac.Owners)
                {
                    MemberViewModel memberVM = new MemberViewModel()
                    {
                        Id           = owner.Id,
                        FirstName    = owner.FirstName,
                        LastName     = owner.LastName,
                        PrimaryEmail = owner.Login.Email,
                        Phone        = owner.Phone,
                        AltPhone     = owner.AltPhone
                    };

                    vmItem.Owners.Add(memberVM);
                }

                viewModel.Add(vmItem);
            }

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