public Passenger RegisterPassenger(Passenger passenger) { bool isValid = ExistsEmail(passenger.Email); if (isValid) { throw new Exception("E-mail já existente"); } return(_repository.Add(passenger)); }
/// <summary> /// Insert flight into a temporal list for then save the flight information in the database of fights and itineraries. /// </summary> /// <param name="model"></param> public void InsertFlightIntoList(BasicItineraryModel model) { var airlineInfo = _airlinesRepository.GetAirlinebyName(model.AirlineName); _airportsRepository = new AirportsRepository(); _passengerRepository = new PassengerRepository(); if (airlineInfo == null) { return; } var airlineId = airlineInfo.AirlineID; var airportInfo1 = _airportsRepository.GetAirportbyName(model.DepartureName); var airportInfo2 = _airportsRepository.GetAirportbyName(model.ArrivalName); if ((airportInfo1 == null) || (airportInfo2 == null)) { return; } var departureLocation = airportInfo1.AirportID; var arrivalLocation = airportInfo2.AirportID; var flight = new Flights { AirlineID = airlineId, DepartureLocation = departureLocation, FlightNumber = model.FlightNumber, ArrivalLocation = arrivalLocation, DepartureDateTime = (DateTime)model.DepartureTime, ArrivalDateTime = (DateTime)model.ArrivalTime, }; _listF.Add(flight); _listIti.Add(model); var passenger = _passengerRepository.Get(model.PassengerEmail); if (passenger == null) { passenger = new Passengers { PassengerEmail = model.PassengerEmail, PassengerLastName = model.PassengerLastName, PassengerName = model.PassengerName, TokenId = "TokenID" }; _passengerRepository.Add(passenger); } }
public async Task <IActionResult> AddPassengers(PassengerViewModel model) { if (ModelState.IsValid) { Reservation reservation = _reservationRepository.Items.SingleOrDefault(item => item.Id == model.Id); Flight flight = _flightRepository.Items.SingleOrDefault(item => item.Id == reservation.FlightId); model.Reservation = reservation; model.ReservationId = reservation.Id; int businessCount = reservation.PassengersBusinessCount; int economyCount = reservation.PassengersEconomyCount; Passenger passenger = new Passenger { ReservationId = model.ReservationId, Reservation = model.Reservation, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, EGN = model.EGN, PhoneNumber = model.PhoneNumber, IsBusiness = model.IsBusiness }; if (passenger.IsBusiness) { flight.CapacityBusinessPassengers--; } else { flight.CapacityEconomyPassengers--; } await _passengerRepository.Add(passenger); reservation.Passengers.Add(passenger); await _reservationRepository.Update(reservation); await _flightRepository.Update(flight); if (reservation.Passengers.Count == (economyCount + businessCount)) { return(View("SuccessfulReservation")); } else { return(RedirectToAction("AddPassengers", reservation)); } } return(View(model)); }
public async Task <ActionResult <PassengerDto> > PostEvent(PassengerDto passengerDto) { try { var mappedEntity = _mapper.Map <Passenger>(passengerDto); _passengerRepository.Add(mappedEntity); if (await _passengerRepository.Save()) { return(Created($"/api/v1.0/Passengers/{mappedEntity.Id}", _mapper.Map <Passenger>(mappedEntity))); } } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}")); } return(BadRequest()); }
public void AddPassenger(string userId, string passFirstName, string passLastName, string passMail, string passAddress, string passCity, string passCountry, int passAge) { Guid userIdGuid = Guid.Empty; if (!Guid.TryParse(userId, out userIdGuid)) { throw new Exception("Invalid Guid Format"); } var customer = customerRepository.GetCustomerByUserId(userIdGuid); if (customer == null) { throw new EntityNotFoundException(userIdGuid); } passengerRepository.Add(new Passenger() { PassengerId = Guid.NewGuid(), FirstName = passFirstName, LastName = passLastName, Address = passAddress, Age = passAge, City = passCity, Country = passCountry, Mail = passMail }); }
/// <summary> /// This Method will Create New Passenger /// </summary> /// <param name="req">req is an object type of Passenger class</param> /// <returns>this will return Passengers object</returns> public Passengers CreatePassenger(Passenger req) { Passengers _passenger = new Passengers(); _passenger.loginAccount = req.loginAccount; _passenger.name = req.name; _passenger.bDay = req.bDay; _passenger.bMonth = req.bMonth; _passenger.bYear = req.bYear; _passenger.sex = req.sex; _passenger.birthPf = req.birthPreferance; _passenger.foodPf = req.foodPreferance; _passenger.idCardTypeId = req.idCardTypeId; _passenger.idCardNumber = req.idCardNumber; _passenger.senior = req.senior; _passengerRepository.Add(_passenger); _passengerRepository.Commit(); return(_passenger); }
public async Task <ActionResult> Checkin([FromBody] CheckinViewModel model) { var flight = await _flightRepository.GetAsync(model.FlightId); var passenger = new Passenger(model.PassengerName, flight); model.Baggages.ForEach(b => { passenger.AddBaggage(b.Label, b.Weight); }); var validationResponse = await _bookingService.ValidateAndEndBookingSessionAsync(model.FlightId, model.BookingSessionId); _passengerRepository.Add(passenger); await _passengerRepository.UnitOfWork.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult <Passenger> > Post([FromBody] Passenger newPassenger) { Passenger passenger = await _passengerRepository.Add(newPassenger); return(Ok(passenger)); }