public async Task <IActionResult> PutFlCompany([FromRoute] int id, [FromBody] FlCompany flCompany)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != flCompany.Cid)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutBooking(int id, Booking booking)
        {
            if (id != booking.Id)
            {
                return(BadRequest());
            }
            _context.Entry(booking).State = EntityState.Modified;

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

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutFlight(int id, Flight flight)
        {
            if (id != flight.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> PutFlight([FromBody] Flight flight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /*if (id != flight.FlightId)
             * {
             *  return BadRequest();
             * }*/

            // _context.Entry(flight).State = EntityState.Modified;

            try
            {
                _context.Flight.Update(flight);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightExists(flight.FlightId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
            public async Task <int> Handle(ExecuteCreateClientFlight request, CancellationToken cancellationToken)
            {
                persistence.ClientFlight clientFlight = new persistence.ClientFlight()
                {
                    ClientId = request.ClientId,
                    FlightId = request.FlightId
                };

                _FlightDBContext.ClientFlights.Add(clientFlight);
                await _FlightDBContext.SaveChangesAsync();

                return(clientFlight.FlightId);
            }
            public async Task <int> Handle(ExecuteCreateTransport request, CancellationToken cancellationToken)
            {
                string flightNumber = new RandomNumber().RandomString(7);

                persistence.Transport transport = new persistence.Transport()
                {
                    FlightNumber = flightNumber
                };

                _FlightDBContext.Transports.Add(transport);
                await _FlightDBContext.SaveChangesAsync();

                return(transport.Id);
            }
Пример #7
0
            public async Task <int> Handle(ExecuteCreateClient request, CancellationToken cancellationToken)
            {
                persistence.Client client = new persistence.Client()
                {
                    Email     = request.Email,
                    FirstName = request.FirstName,
                    LastName  = request.LastName,
                    Phone     = request.Phone
                };

                _FlightDBContext.Clients.Add(client);
                await _FlightDBContext.SaveChangesAsync();

                return(client.Id);
            }
Пример #8
0
        public async Task <IActionResult> PutFlBooking([FromRoute] int id, [FromBody] FlBooking flBooking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != flBooking.BookingId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException uex)
            {
                if (!FlBookingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw uex;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(NoContent());
        }
Пример #9
0
            public async Task <ResponseMessage> Handle(ExecuteEditClient request, CancellationToken cancellationToken)
            {
                var client = await _FlightDBContext.Clients.Where(x => x.Id == Convert.ToInt32(request.Id)).FirstOrDefaultAsync();

                client.Phone = request.Phone;
                client.Email = request.Email;

                _FlightDBContext.Clients.Attach(client);
                await _FlightDBContext.SaveChangesAsync();

                return(new ResponseMessage()
                {
                    Success = true,
                    Message = "Cambios guardados"
                });
            }
Пример #10
0
            public async Task <ResponseMessage> Handle(ExecuteCreateFligh request, CancellationToken cancellationToken)
            {
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    int transportId = await _IMediator.Send(new CreateTransport.ExecuteCreateTransport());

                    persistence.Flight flight = new persistence.Flight()
                    {
                        ArrivalStation   = request.ArrivalStation,
                        Currency         = request.Currency,
                        DepartureDate    = request.DepartureDate,
                        DepartureStation = request.DepartureStation,
                        Price            = request.Price,
                        TransportId      = transportId
                    };

                    _FlightDBContext.Flights.Add(flight);
                    await _FlightDBContext.SaveChangesAsync();

                    foreach (var item in request.ListClient)
                    {
                        int clientId = await _IMediator.Send(new CreateClient.ExecuteCreateClient()
                        {
                            Email     = item.Email,
                            FirstName = item.FirstName,
                            LastName  = item.LastName,
                            Phone     = item.Phone
                        });

                        int clientFlightId = await _IMediator.Send(new CreateClientFlight.ExecuteCreateClientFlight()
                        {
                            ClientId = clientId,
                            FlightId = flight.Id
                        });
                    }

                    scope.Complete();
                    return(new ResponseMessage()
                    {
                        Message = "Compra exitosa",
                        Success = true
                    });
                }
            }