示例#1
0
        public Task <Crew> GetById(int id)
        {
            if (id <= 0)
            {
                throw new ArgumentException("id must be more than 0");
            }

            return(_crewRepository.GetById(id));
        }
        public async Task ExecuteAsync(DeleteCrewCommand command)
        {
            var crew = await _crewRepository.GetById(command.CrewId);

            if (crew == null)
            {
                throw new Exception("Crew with this Id does not exist");
            }

            await _crewRepository.Delete(crew);
        }
        public async Task <CrewByIdResponse> ExecuteAsync(CrewByIdQuery request)
        {
            var crew = await _crewRepository.GetById(request.CrewId);

            if (crew == null)
            {
                throw new Exception("Idea not found");
            }

            var mappedCrew = _mapper.Map <CrewByIdResponse>(crew);

            return(mappedCrew);
        }
        public async Task ExecuteAsync(UpdateCrewCommand command)
        {
            var crew = await _crewRepository.GetById(command.CrewId);

            if (crew == null)
            {
                throw new Exception("Crew with this Id does not exist");
            }

            crew.Pilot        = _pilotRepository.GetById(command.PilotId).Result;
            crew.Stewardesses = _stewardessRepository.GetAll().Where(y => command.StewardressesId.Contains(y.Id));

            await _crewRepository.Update(crew);
        }
        public async Task ExecuteAsync(CreateCrewCommand command)
        {
            if (await _crewRepository.GetById(command.Id) != null)
            {
                throw new Exception("Crew with same Id already exists");
            }

            var crew = new Domain.Entities.Crew
            {
                Id           = command.Id,
                Pilot        = await _pilotRepository.GetById(command.PilotId),
                Stewardesses = await _stewardessRepository.GetAll().Where(y => command.StewardressesId.Contains(y.Id)).ToListAsync()
            };

            await _crewRepository.Create(crew);
        }
示例#6
0
 public async Task <CrewReadResource> GetCrew(int id)
 {
     return(await repo.GetById(id));
 }