Пример #1
0
        public async Task AddTicketAsync(NewTicketModel model)
        {
            var ticket = _mapper.Map <Ticket>(model);

            _context.Tickets.Add(ticket);
            await _context.SaveChangesAsync();
        }
Пример #2
0
        public async Task <IHttpActionResult> PutClient(int id, Client client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != client.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IActionResult> PutAirport([FromRoute] int id, [FromBody] Airport airport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != airport.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #4
0
        public async Task AddTicketTypeAsync(TicketTypeViewModel model)
        {
            var ticketType = _mapper.Map <TicketType>(model);

            _context.TicketTypes.Add(ticketType);
            await _context.SaveChangesAsync();
        }
Пример #5
0
        public async Task <int> AddFlightAsync(NewFlightModel model)
        {
            var flight = _mapper.Map <Flight>(model);

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

            return(flight.Id);
        }
Пример #6
0
        public async Task <int> AddAirplaneAsync(AirplaneViewModel model)
        {
            var airplane = _mapper.Map <Airplane>(model);

            _context.Airplanes.Add(airplane);
            await _context.SaveChangesAsync();

            return(airplane.Id);
        }
Пример #7
0
        public async Task <IActionResult> AddAc([Bind("AcID,AcModel,AcType,AcCapacity,AcRegisterDate,AcModifiedDate")] Aircraft aircraft)
        {
            if (ModelState.IsValid)
            {
                aircraft.AcRegisterDate = DateTime.Now;
                ctx.Add(aircraft);
                await ctx.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aircraft));
        }
Пример #8
0
        public async Task <IActionResult> AddFlg(Flight vmFr)
        {
            if (ModelState.IsValid)
            {
                ctx.Flights.Add(vmFr);
                await ctx.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AcID"] = new SelectList(ctx.Aircrafts, "AcID", "AcModel", vmFr.AcID);
            return(View(vmFr));
        }
Пример #9
0
        public async Task Handle(CancelLinkedCarFailed message, IMessageHandlerContext context)
        {
            log.Info($"Received CancelLinkedCarFailed, CombinedReservationId = ");

            List <Airline> companies = _context.AirlineCompanies
                                       .Include(comp => comp.FastTickets)
                                       .Include(comp => comp.Destinations)
                                       .Include(comp => comp.PopDestinaations)
                                       .Include(comp => comp.Raters)
                                       .Include(comp => comp.Flights).ThenInclude(f => f.Luggage)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.From)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.To)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Stops)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.AllTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Seats).ThenInclude(d => d.Traveller)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .ToList();


            foreach (var c in companies)
            {
                foreach (var f in c.Flights)
                {
                    foreach (var rez in f.AllTickets)
                    {
                        if (rez.Id == message.idRez)
                        {
                            rez.userId  = message.userId;
                            rez.reqTick = message.ticket.ToString();
                            await _context.SaveChangesAsync();
                        }
                    }
                }
            }

            foreach (var u in companies)
            {
                foreach (var u2 in u.Flights)
                {
                    foreach (var u3 in u2.Seats)
                    {
                        if (message.seatId == u3.Id)
                        {
                            u3.Taken = true;
                            await _context.SaveChangesAsync();
                        }
                    }
                }
            }
        }
Пример #10
0
        public async Task <IActionResult> AddEmp([Bind("EmpID,EmpName,EmpLastName,EmpGender,EmpHomeAdrs,EmpPhoneNumber,EmpEmail,EmpBirthdate,EmpHireDate,EmpModifiedDate,EmpCardID,EmpSalary,EmpType")] Employee emp)
        {
            if (ModelState.IsValid)
            {
                emp.EmpHireDate = DateTime.Now;
                ctx.Add(emp);
                await ctx.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(emp));
        }
        public async Task <IActionResult> Create([Bind("BookingID,FlightNumber,PassengerName,DepartingAirport,ArrivalAirport,CreatedDate,JourneyDate,MealPreference,EmailAddress")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FlightNumber"] = new SelectList(_context.Flights, "FlightNumber", "FlightDestinationAirport", booking.FlightNumber);
            return(View(booking));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("ID,UserName,Password,Email,Role")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                string password = Crypto.HashPassword(user.Password);
                user.Password = password;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Пример #13
0
        public async Task AddSeatsAsync(SeatViewModel[] seatsModel)
        {
            var seats = _mapper.Map <List <Seat> >(seatsModel);

            _context.Seats.AddRange(seats);
            await _context.SaveChangesAsync();
        }
Пример #14
0
        public async Task <AccountEntity> CreateAccountAsync(AccountEntity account)
        {
            await _context.AddAsync(account);

            await _context.SaveChangesAsync();

            return(account);
        }
Пример #15
0
        public async Task <IActionResult> Create([Bind("FlightId,AirportStart,AirportEnd,FlightDate,FlightTime,NumFCSeats,FCSeatPrice,NumBusSeats,BusSeatPrice")] Flight flight, string AirportStart, string AirportEnd)
        {
            if (ModelState.IsValid)
            {
                var    startAirport = _context.Airports.First(m => m.IATA == AirportStart);
                var    stopAirport  = _context.Airports.First(m => m.IATA == AirportEnd);
                double latStart     = startAirport.Latitude;
                double lonStart     = startAirport.Longitude;
                double latEnd       = stopAirport.Latitude;
                double lonEnd       = stopAirport.Longitude;
                flight.TravelDistance = GeoDistance.Calculate(latStart, lonStart, latEnd, lonEnd, 'M');

                flight.AirportStart = startAirport;
                flight.AirportEnd   = stopAirport;
                _context.Add(flight);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            //ViewBag.Message = "Flight Added!";
            return(View(flight));
        }
Пример #16
0
        public async Task <Response <string> > UpdateUserAsync(int id, UpdateUserModel model)
        {
            var user = await _context.Users.FindAsync(id);

            if (user == null || user.Status == "Deleted")
            {
                return(new Response <string>
                {
                    Success = false,
                    Message = "There is no such user"
                });
            }

            _mapper.Map(model, user);
            await _context.SaveChangesAsync();

            return(new Response <string>
            {
                Success = true,
                Message = "User was succesfully updated"
            });
        }
Пример #17
0
        public async Task <List <TicketWasBookedResponseModel> > AddBookedTicketAsync(NewBookedTicketModel[] models)
        {
            var bookedTickets = _mapper.Map <List <BookedTicket> >(models);

            _context.BookedTickets.AddRange(bookedTickets);
            await _context.SaveChangesAsync();

            List <TicketWasBookedResponseModel> reponse = new List <TicketWasBookedResponseModel>();

            foreach (var ticket in bookedTickets)
            {
                reponse.Add(new TicketWasBookedResponseModel {
                    Id = ticket.Id,
                    PassengerFirstName = ticket.PassengerFirstName,
                    PassengerLastName  = ticket.PassengerLastName
                });
            }

            return(reponse);
        }
Пример #18
0
        public async Task Add(TEntity entity)
        {
            await db.Set <TEntity>().AddAsync(entity);

            await db.SaveChangesAsync();
        }
Пример #19
0
 public async Task AddAirportAsync(Airport airport)
 {
     _context.Airports.Add(airport);
     await _context.SaveChangesAsync();
 }