Example #1
0
        public async Task <IActionResult> PostAirport([FromBody] Airportt airportt)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                if (airportt.AirportID == Guid.Empty)
                {
                    airportt.AirportID = Guid.NewGuid();
                    _context.Airportts.Add(airportt);

                    await _context.SaveChangesAsync();

                    return(Json(new { success = true, message = "Add new data success." }));
                }
                else
                {
                    _context.Update(airportt);

                    await _context.SaveChangesAsync();

                    return(Json(new { success = true, message = "Edit data success." }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }));
            }
        }
 public IActionResult AddEdit(Guid id)
 {
     if (id == Guid.Empty)
     {
         Airportt airport = new Airportt();
         return(View(airport));
     }
     else
     {
         return(View(_DBcontext.Airportts.Where(x => x.AirportID.Equals(id)).FirstOrDefault()));
     }
 }
        public IActionResult GetFlight()
        {
            List<FlightDataTableModel> flights = new List<FlightDataTableModel>();

            foreach(Flight f in _context.Flights.ToList())
            {
                FlightDataTableModel fl = new FlightDataTableModel();
                fl.FligthID = f.FligthID;
                fl.DepartureDate = f.DepartureDate;
                fl.DestinationDate = f.DestinationDate;
                fl.AirplaneType = _context.Airplanes.FirstOrDefault(x => x.AirplaneID.Equals(f.AirplaneID)).AirplaneType;

                Airportt airportFrom = _context.Airportts.FirstOrDefault(x => x.AirportID.Equals(f.AirportFromAirportID));
                Airportt airportTo = _context.Airportts.FirstOrDefault(x => x.AirportID.Equals(f.AirportToAirportID));
                fl.AirportFrom = airportFrom.AirportName + "( " + airportFrom.CountryName + ", " + airportFrom.CityName + ")" ;
                fl.AirportTo = airportTo.AirportName + "( " + airportTo.CountryName + ", " + airportTo.CityName + ")";
                fl.FlightTime = _context.TimeTables.FirstOrDefault(x => x.TimeTableID.Equals(f.TimeTableID)).FlightTime;
                fl.PriceFlight = f.PriceFlight;

                flights.Add(fl);
            }
            return Json(new { data = flights });
        }
        public async Task<IActionResult> PostFlight([FromBody] Flight flight)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                Airportt airport = _context.Airportts.SingleOrDefault(x => x.AirportID == flight.AirportToAirportID);
                flight.AirportToAirportID = airport.AirportID;
                if (flight.FligthID == Guid.Empty)
                {
                    flight.FligthID = Guid.NewGuid();
                    _context.Flights.Add(flight);

                    await _context.SaveChangesAsync();

                    return Json(new { success = true, message = "Add new data success." });
                }
                else
                {
                    _context.Update(flight);

                    await _context.SaveChangesAsync();

                    return Json(new { success = true, message = "Edit data success." });
                }
            }
            catch (Exception ex)
            {

                return Json(new { success = false, message = ex.Message });
            }

        }
Example #5
0
        public IActionResult GetTickets()
        {
            List <TicketDataTableModel> tickets = new List <TicketDataTableModel>();

            foreach (Ticket t in _context.Ticket.ToList())
            {
                TicketDataTableModel model = new TicketDataTableModel();
                Flight   f           = _context.Flights.FirstOrDefault(x => x.FligthID.Equals(t.FlightFligthID));
                Airportt airportFrom = _context.Airportts.FirstOrDefault(x => x.AirportID.Equals(f.AirportFromAirportID));
                Airportt airportTo   = _context.Airportts.FirstOrDefault(x => x.AirportID.Equals(f.AirportToAirportID));

                model.TicketID      = t.TicketID;
                model.Seat          = t.Seat;
                model.Price         = t.Price;
                model.OrderDate     = t.OrderDate;
                model.User          = _context.User.FirstOrDefault(x => x.UserId.Equals(t.UserId));
                model.AirportFrom   = airportFrom.AirportName + "( " + airportFrom.CountryName + ", " + airportFrom.CityName + ")";
                model.AirportTo     = airportTo.AirportName + "( " + airportTo.CountryName + ", " + airportTo.CityName + ")";
                model.DepartureDate = f.DepartureDate;

                tickets.Add(model);
            }
            return(Json(new { data = tickets }));
        }