Пример #1
0
        public async Task <IActionResult> PutCountry(int id, Country country)
        {
            if (id != country.Id)
            {
                return(BadRequest());
            }

            _context.Entry(country).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CountryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IHttpActionResult> PutDestination(string id, Destination destination)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != destination.ZipCode)
            {
                return(BadRequest());
            }

            db.Entry(destination).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DestinationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IHttpActionResult> PutFlightPlace(int id, FlightPlace flightPlace)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != flightPlace.numPlace)
            {
                return(BadRequest());
            }

            db.Entry(flightPlace).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightPlaceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public async Task <IActionResult> PutPassenger(int id, Passenger passenger)
        {
            if (id != passenger.Passport)
            {
                return(BadRequest());
            }

            _context.Entry(passenger).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PassengerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public async Task <IHttpActionResult> PutCommercialFlight(string id, CommercialFlight commercialFlight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != commercialFlight.IdFlight)
            {
                return(BadRequest());
            }

            db.Entry(commercialFlight).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommercialFlightExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,Lastname,IdentifiactionalNumber,PhoneNumber,Email")] Reservations reservations)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservations);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservations));
        }
        public async Task <IActionResult> Create([Bind("PlaneId,LocationFrom,LocationTo,DepartTime,ArrivalTime,PlaneType,PilotName,PlaneCapacityNormal,PlaneCapacityBusiness,AlreadyReserved")] Flights flights)
        {
            if (ModelState.IsValid)
            {
                _context.Add(flights);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flights));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("StopId,StopLocation")] Stop stop)
        {
            if (ModelState.IsValid)
            {
                stop.StopId = Guid.NewGuid();
                _context.Add(stop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stop));
        }
        public async Task <IActionResult> Create([Bind("LineId,Name")] Line line)
        {
            if (ModelState.IsValid)
            {
                line.LineId = Guid.NewGuid();
                _context.Add(line);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(line));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("RouteId,DepartureLocation,DestinationLocation")] Route route)
        {
            if (ModelState.IsValid)
            {
                route.RouteId = Guid.NewGuid();
                _context.Add(route);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(route));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("CardId,ClientId,ExpirationDate,Number,CVC")] Card card)
        {
            if (ModelState.IsValid)
            {
                card.CardId = Guid.NewGuid();
                _context.Add(card);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Id", card.ClientId);
            return(View(card));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("PlaneId,Model,Manufacturer,LineId")] Plane plane)
        {
            if (ModelState.IsValid)
            {
                plane.PlaneId = Guid.NewGuid();
                _context.Add(plane);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LineId"] = new SelectList(_context.Lines, "LineId", "LineId", plane.LineId);
            return(View(plane));
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("BookingId,ClientId,RouteId,PaymentDate,PaymentMethod,FlightClass,BookingDate")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                booking.BookingId = Guid.NewGuid();
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Id", booking.ClientId);
            ViewData["RouteId"]  = new SelectList(_context.Routes, "RouteId", "RouteId", booking.RouteId);
            return(View(booking));
        }
        public async Task <IActionResult> Create([Bind("FlightId,PlaneId,RouteId,DepartureDate,DepartureHour,DestinationHour")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                flight.FlightId = Guid.NewGuid();
                _context.Add(flight);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlaneId"] = new SelectList(_context.Planes, "PlaneId", "PlaneId", flight.PlaneId);
            ViewData["RouteId"] = new SelectList(_context.Routes, "RouteId", "RouteId", flight.RouteId);
            return(View(flight));
        }
Пример #15
0
        public async Task <IActionResult> Create([Bind("Route_StopId,StopId,RouteId,StopTime")] Route_Stop route_Stop)
        {
            if (ModelState.IsValid)
            {
                route_Stop.Route_StopId = Guid.NewGuid();
                _context.Add(route_Stop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouteId"] = new SelectList(_context.Routes, "RouteId", "RouteId", route_Stop.RouteId);
            ViewData["StopId"]  = new SelectList(_context.Stops, "StopId", "StopId", route_Stop.StopId);
            return(View(route_Stop));
        }
Пример #16
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,Lastname,Nationality,IdentificationalNumber,PhoneNumber,Email,FlightNumber,TicketType")] Reservations reservations)
        {
            if (ModelState.IsValid)
            {
                int business = _context.Flights.Find(reservations.FlightNumber).PlaneCapacityBusiness;
                int economy  = _context.Flights.Find(reservations.FlightNumber).PlaneCapacityNormal;
                if (reservations.TicketType == "Economy")
                {
                    if (_context.Flights.Find(reservations.FlightNumber).PlaneCapacityNormal > 0)
                    {
                        _context.Flights.Find(reservations.FlightNumber).PlaneCapacityNormal -= 1;
                        _context.Flights.Find(reservations.FlightNumber).AlreadyReserved     += 1;
                        await _context.SaveChangesAsync();

                        Mailer.SendMail(reservations);
                    }
                    else
                    {
                        return(View(_context.Flights));
                    }
                }
                else if (reservations.TicketType == "Business")
                {
                    if (_context.Flights.Find(reservations.FlightNumber).PlaneCapacityBusiness > 0)
                    {
                        _context.Flights.Find(reservations.FlightNumber).PlaneCapacityBusiness -= 1;
                        _context.Flights.Find(reservations.FlightNumber).AlreadyReserved       += 1;
                        await _context.SaveChangesAsync();

                        Mailer.SendMail(reservations);
                    }
                    else
                    {
                        return(View(_context.Flights));
                    }
                }
                else
                {
                    return(View(_context.Flights));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservations));
        }
Пример #17
0
        public async Task <ActionResult <Server> > PostServer(Server server)
        {
            serverContext.Servers.Add(server);
            try
            {
                await serverContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ServerExists(server.serverID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetServer", new { id = server.serverID }, server));
        }
Пример #18
0
        public async Task <ActionResult <FlightPlan> > PostFlightPlan(FlightPlan flightPlan)
        {
            if (!flightManager.CheckIfFlightPlanIsValid(flightPlan))
            {
                return(BadRequest("the flight plan format is wrong. did you forget a field?"));
            }
            string newID = flightManager.GenerateRandomID();

            flightPlan.FlightID = newID;


            flightContext.FlightsPlans.Add(flightPlan);

            Flight flightFromFlightPlan = flightManager.CreateNewFlight(flightPlan);


            flightContext.Flights.Add(flightFromFlightPlan);

            await flightContext.SaveChangesAsync();

            return(CreatedAtAction("GetFlightPlan", new { id = flightPlan.FlightID }, flightPlan));
        }
        public async Task SeedAsync(FlightsContext context, ILogger <FlightsContextSeed> logger)
        {
            var policy = CreatePolicy(logger, nameof(FlightsContextSeed));

            await policy.ExecuteAsync(async() =>
            {
                using (context)
                {
                    context.Database.Migrate();

                    if (!context.Flights.Any())
                    {
                        context.Flights.AddRange(GetFlights());

                        await context.SaveChangesAsync();
                    }
                }
            });
        }
Пример #20
0
        public async Task AddFlightAsync(Flight flight)
        {
            await _context.Flights.AddAsync(flight);

            await _context.SaveChangesAsync();
        }