public async Task <ResultTypes> AddFlightSeatTypeCostAsync(FlightSeatTypeCost seatTypeCost) { FlightSeatTypeCostEntity seatTypeCostDal = _mapper.Map <FlightSeatTypeCostEntity>(seatTypeCost); FlightEntity flight = await _flightRepository.GetByIdAsync(seatTypeCostDal.FlightId); if (flight == null) { return(ResultTypes.NotFound); } AirplaneSeatTypeEntity seatType = await _airplaneRepository.GetSeatTypeById(seatTypeCostDal.SeatTypeId); if (seatType == null) { return(ResultTypes.NotFound); } bool duplicate = await _flightRepository.CheckFlightSeatTypeCostDuplicateAsync(seatTypeCostDal); if (duplicate) { return(ResultTypes.Duplicate); } await _flightRepository.AddFlightSeatTypeCostAsync(seatTypeCostDal); return(ResultTypes.Ok); }
public async Task <bool> CheckSeatTypeDuplicateAsync(AirplaneSeatTypeEntity seatType) { AirplaneSeatTypeEntity duplicate = _airplaneSeatTypeData.FirstOrDefault( x => x.Name == seatType.Name && x.AirplaneId == seatType.AirplaneId ); return(duplicate != null); }
public async Task <bool> CheckSeatTypeDuplicateAsync(AirplaneSeatTypeEntity seatType) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.ExecuteScalarAsync <bool>( "CheckSeatTypeDuplicate", new { airplaneId = seatType.AirplaneId, name = seatType.Name, color = seatType.Color }, commandType : CommandType.StoredProcedure)); }
public async Task <int> AddAirplaneSeatTypeAsync(AirplaneSeatTypeEntity seatType) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.QuerySingleOrDefaultAsync <int>( "AddAirplaneSeatType", new { airplaneId = seatType.AirplaneId, name = seatType.Name, color = seatType.Color }, commandType : CommandType.StoredProcedure)); }
public async Task <ResultTypes> UpdateAirplaneSeatsAsync(int airplaneId, AirplaneSeat[] seats) { AirplaneEntity updatingAirplane = await _airplaneRepository.GetByIdAsync(airplaneId); if (updatingAirplane == null) { return(ResultTypes.NotFound); } // checks if all seats from 'seats' array have unique position bool unique = seats .GroupBy(x => new { x.AirplaneId, x.Floor, x.Section, x.Zone, x.Row, x.Number }) .All(g => g.Count() == 1); if (!unique) { return(ResultTypes.Duplicate); } bool existingSeatTypes = true; foreach (AirplaneSeat seat in seats) { AirplaneSeatTypeEntity seatType = await _airplaneRepository.GetSeatTypeById(seat.TypeId); if (seatType == null) { existingSeatTypes = false; break; } } if (!existingSeatTypes) { return(ResultTypes.NotFound); } await _airplaneRepository.DeleteAirplaneSeatsAsync(airplaneId); AirplaneSeatEntity[] seatsDal = seats.Select(_mapper.Map <AirplaneSeatEntity>).ToArray(); await _airplaneRepository.UpdateAirplaneSeatsAsync(airplaneId, seatsDal); return(ResultTypes.Ok); }
public async Task <AddResult> AddAirplaneSeatTypeAsync(AirplaneSeatType seatType) { AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(seatType.AirplaneId); if (airplane == null) { return(new AddResult(ResultTypes.NotFound, null)); } AirplaneSeatTypeEntity seatTypeDal = _mapper.Map <AirplaneSeatTypeEntity>(seatType); bool duplicate = await _airplaneRepository.CheckSeatTypeDuplicateAsync(seatTypeDal); if (duplicate) { return(new AddResult(ResultTypes.Duplicate, null)); } int addedAirplaneSeatTypeId = await _airplaneRepository.AddAirplaneSeatTypeAsync(seatTypeDal); return(new AddResult(ResultTypes.Ok, addedAirplaneSeatTypeId)); }
public async Task <ResultTypes> UpdateFlightSeatTypeCostAsync(FlightSeatTypeCost newSeatTypeCost) { FlightSeatTypeCostEntity seatTypeCostDal = _mapper.Map <FlightSeatTypeCostEntity>(newSeatTypeCost); FlightEntity flight = await _flightRepository.GetByIdAsync(seatTypeCostDal.FlightId); if (flight == null) { return(ResultTypes.NotFound); } AirplaneSeatTypeEntity seatType = await _airplaneRepository.GetSeatTypeById(seatTypeCostDal.SeatTypeId); if (seatType == null) { return(ResultTypes.NotFound); } await _flightRepository.UpdateFlightSeatTypeCostAsync(seatTypeCostDal); return(ResultTypes.Ok); }
public async Task <int> AddAirplaneSeatTypeAsync(AirplaneSeatTypeEntity seatType) { return(0); }
public async Task <AirplaneSeatType> GetSeatTypeByIdAsync(int seatTypeId) { AirplaneSeatTypeEntity seatTypeDal = await _airplaneRepository.GetSeatTypeById(seatTypeId); return(_mapper.Map <AirplaneSeatType>(seatTypeDal)); }