예제 #1
0
        public async Task <ResultTypes> UpdateAsync(Flight newFlight)
        {
            FlightEntity flightDal = _mapper.Map <FlightEntity>(newFlight);

            AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId);

            AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId);

            if (toAirport == null || fromAirport == null)
            {
                return(ResultTypes.NotFound);
            }

            AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId);

            if (airplane == null)
            {
                return(ResultTypes.NotFound);
            }

            if (newFlight.ArrivalTime <= newFlight.DepartureTime)
            {
                return(ResultTypes.InvalidData);
            }

            await _flightRepository.UpdateAsync(flightDal);

            return(ResultTypes.Ok);
        }
        public static async Task <IActionResult> UpdateAirplane([HttpTrigger(AuthorizationLevel.Function, "put", Route = "airplanes/{regNo}")] HttpRequest req, string regNo, ILogger log)
        {
            log.LogInformation($"Update existing airplane request");

            try
            {
                string         _RequestBody = await new StreamReader(req.Body).ReadToEndAsync();
                AirplaneEntity _Entity      = JsonConvert.DeserializeObject <AirplaneEntity>(_RequestBody);

                if (await AirplaneRepo.Get(regNo) != null)
                {
                    await AirplaneRepo.Update(regNo, _Entity);
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
                return(new NotFoundResult());
            }

            return(new OkResult());
        }
예제 #3
0
        public async Task <AddResult> AddAsync(Flight flight)
        {
            FlightEntity flightDal = _mapper.Map <FlightEntity>(flight);

            AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId);

            AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId);

            if (toAirport == null || fromAirport == null)
            {
                return(new AddResult(ResultTypes.NotFound, null));
            }

            AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId);

            if (airplane == null)
            {
                return(new AddResult(ResultTypes.NotFound, null));
            }

            if (flight.ArrivalTime <= flight.DepartureTime)
            {
                return(new AddResult(ResultTypes.InvalidData, null));
            }

            int addedFlightId = await _flightRepository.AddAsync(flightDal);

            return(new AddResult(ResultTypes.Ok, addedFlightId));
        }
예제 #4
0
        public async Task <Airplane> GetByIdAsync(int id)
        {
            AirplaneEntity airplaneDal = await _airplaneRepository.GetByIdAsync(id);

            Airplane airplane = _mapper.Map <Airplane>(airplaneDal);

            return(airplane);
        }
예제 #5
0
        public async Task UpdateAsync(AirplaneEntity airplane)
        {
            using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString);

            await db.ExecuteAsync(
                "UpdateAirplane",
                airplane,
                commandType : CommandType.StoredProcedure);
        }
예제 #6
0
        public async Task <int> AddAsync(AirplaneEntity airplane)
        {
            using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString);

            return(await db.QuerySingleOrDefaultAsync <int>(
                       "AddAirplane",
                       new { name = airplane.Name, carryingKg = airplane.CarryingKg },
                       commandType : CommandType.StoredProcedure));
        }
예제 #7
0
        public async Task <bool> CheckAirplaneDuplicateAsync(AirplaneEntity airplane)
        {
            using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString);

            return(await db.ExecuteScalarAsync <bool>(
                       "CheckAirplaneDuplicate",
                       new { Name = airplane.Name },
                       commandType : CommandType.StoredProcedure));
        }
예제 #8
0
        public async Task <ResultTypes> DeleteAirplaneSeatTypeAsync(int airplaneId, int seatTypeId)
        {
            AirplaneEntity airplaneDal = await _airplaneRepository.GetByIdAsync(airplaneId);

            if (airplaneDal == null)
            {
                return(ResultTypes.NotFound);
            }

            await _airplaneRepository.DeleteAirplaneSeatTypeAsync(airplaneId, seatTypeId);

            return(ResultTypes.Ok);
        }
예제 #9
0
 public async Task Update(string regNo, AirplaneEntity airplane)
 {
     var serializerSettings = new JsonSerializerSettings()
     {
         NullValueHandling    = NullValueHandling.Ignore,
         DefaultValueHandling = DefaultValueHandling.Ignore
     };
     var bson = new BsonDocument()
     {
         { "$set", BsonDocument.Parse(JsonConvert.SerializeObject(airplane, serializerSettings)) }
     };
     await _AirplanesCollection.UpdateOneAsync(Builders <AirplaneEntity> .Filter.Eq(plane => plane.RegNo, regNo), bson);
 }
예제 #10
0
        public HttpResponseMessage Post([FromBody] string value)
        {
            try
            {
                //add schedule
                ScheduleEntity scheEntity = (ScheduleEntity)JsonConvert.DeserializeObject <ScheduleEntity>(value);
                Schedule       sche       = new Schedule();
                sche.AirplaneID        = scheEntity.AirplaneID;
                sche.Airport_Arrival   = scheEntity.Airport_Arrival.ToString();
                sche.Airport_Departure = scheEntity.Airport_Departure.ToString();
                sche.Time_Arrival      = scheEntity.Time_Arrival;
                sche.Time_Departure    = scheEntity.Time_Departure;
                entity.Schedules.Add(sche);
                entity.SaveChanges();

                sche.ScheduleID = (int)entity.Schedules.OrderByDescending(x => x.ScheduleID).Select(x => x.ScheduleID).First();
                AirplaneEntity airplaneDetails = entity.AirPlanes.Where(x => x.AirplaneID == sche.AirplaneID).Select(x => new AirplaneEntity
                {
                    Seats_Economy    = x.Seats_Economy,
                    Seats_FirstClass = x.Seats_FirstClass
                }).FirstOrDefault();

                //add seats
                Seat seatDetails;
                for (int i = 0; i < airplaneDetails.Seats_Economy; i++)
                {
                    seatDetails               = new Seat();
                    seatDetails.ScheduleID    = sche.ScheduleID;
                    seatDetails.SeatType      = "Y";
                    seatDetails.CurrentStatus = 0;
                    entity.Seats.Add(seatDetails);
                }

                for (int i = 0; i < airplaneDetails.Seats_FirstClass; i++)
                {
                    seatDetails               = new Seat();
                    seatDetails.ScheduleID    = sche.ScheduleID;
                    seatDetails.SeatType      = "C";
                    seatDetails.CurrentStatus = 0;
                    entity.Seats.Add(seatDetails);
                }
                entity.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
예제 #11
0
        public async Task <AddResult> AddAsync(Airplane airplane)
        {
            AirplaneEntity airplaneDal = _mapper.Map <AirplaneEntity>(airplane);

            bool duplicate = await _airplaneRepository.CheckAirplaneDuplicateAsync(airplaneDal);

            if (duplicate)
            {
                return(new AddResult(ResultTypes.Duplicate, null));
            }

            int addedAirplaneId = await _airplaneRepository.AddAsync(airplaneDal);

            return(new AddResult(ResultTypes.Ok, addedAirplaneId));
        }
예제 #12
0
        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 static async Task <IActionResult> AddNewAirplane([HttpTrigger(AuthorizationLevel.Function, "post", Route = "airplanes/")] HttpRequest req, ILogger log)
        {
            log.LogInformation($"Add new airplane request");

            try
            {
                string         _RequestBody = await new StreamReader(req.Body).ReadToEndAsync();
                AirplaneEntity _Entity      = JsonConvert.DeserializeObject <AirplaneEntity>(_RequestBody);
                await AirplaneRepo.Create(_Entity);
            }
            catch (Exception _Exception)
            {
                log.LogError("Error in Deserializing");
                log.LogError(_Exception.Message);
                return(new BadRequestResult());
            }

            return(new OkResult());
        }
        public static async Task <IActionResult> GetSingleAirplane([HttpTrigger(AuthorizationLevel.Function, "get", Route = "airplanes/{regNo}/")] HttpRequest req, string regNo, ILogger log)
        {
            log.LogInformation($"GET single airplane {regNo}");

            AirplaneEntity _Result = null;

            try
            {
                _Result = await AirplaneRepo.Get(regNo);
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
            }

            if (_Result == null)
            {
                return(new NotFoundResult());
            }

            return(new JsonResult(_Result));
        }
예제 #15
0
        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));
        }
예제 #16
0
        public async Task <ResultTypes> UpdateAsync(Airplane airplane)
        {
            AirplaneEntity airplaneDal = _mapper.Map <AirplaneEntity>(airplane);

            // checks if user tries to update airplane to already existent airplane
            bool duplicate = await _airplaneRepository.CheckAirplaneDuplicateAsync(airplaneDal);

            if (duplicate)
            {
                return(ResultTypes.Duplicate);
            }

            // checks if user tries to update nonexistent airplane
            AirplaneEntity oldAirplaneDal = await _airplaneRepository.GetByIdAsync(airplaneDal.Id);

            if (oldAirplaneDal == null)
            {
                return(ResultTypes.NotFound);
            }

            await _airplaneRepository.UpdateAsync(airplaneDal);

            return(ResultTypes.Ok);
        }
예제 #17
0
 public async Task Update(AirplaneEntity entity)
 {
     using IDbConnection db = _configuration.GetConnection();
     await db.ExecuteAsync("UpdateAirplane", entity, commandType : CommandType.StoredProcedure);
 }
예제 #18
0
 public async Task Remove(AirplaneEntity airplane)
 {
     await _AirplanesCollection.DeleteOneAsync(plane => plane.Id == airplane.Id);
 }
예제 #19
0
        public async Task <AirplaneEntity> Create(AirplaneEntity airplane)
        {
            await _AirplanesCollection.InsertOneAsync(airplane);

            return(airplane);
        }
 public async Task UpdateAsync(AirplaneEntity airplane)
 {
     // implementation
 }
 public async Task <int> AddAsync(AirplaneEntity airplane)
 {
     return(0);
 }
        public async Task <bool> CheckAirplaneDuplicateAsync(AirplaneEntity airplane)
        {
            AirplaneEntity duplicate = _airplaneData.FirstOrDefault(x => x.Name == airplane.Name);

            return(duplicate != null);
        }
예제 #23
0
 public static Airplane ToModel(this AirplaneEntity model) => Mapper.Map <Airplane>(model);