Esempio n. 1
0
        public async Task <List <Logic.FlightTicket> > ReadTicketList(Logic.FlightTicket ticket)
        {
            if (ticket == null)
            {
                List <FlightTicket> ticketFind = await dbcontext.FlightTicket.ToListAsync();

                return(ticketFind.Select(Mapper.MapEToFlightTicket).ToList());
            }
            if (ticket.TicketID <= 0)
            {
                IQueryable <FlightTicket> e_ticket = dbcontext.FlightTicket.Select(t => t);

                if (ticket.FlightID > 0)
                {
                    e_ticket = e_ticket.Where(t => t.FlightID == ticket.FlightID)
                               .AsNoTracking();
                }
                if (ticket.CustomerID > 0)
                {
                    e_ticket = e_ticket.Where(f => f.CustomerID == ticket.CustomerID)
                               .AsNoTracking();
                }
                if (ticket.Luggage > 0)
                {
                    e_ticket = e_ticket.Where(f => f.Luggage == ticket.Luggage)
                               .AsNoTracking();
                }
                if (ticket.Price > 0)
                {
                    e_ticket = e_ticket.Where(f => f.Price == ticket.Price)
                               .AsNoTracking();
                }
                if (ticket.Checkin == true)
                {
                    e_ticket = e_ticket.Where(f => f.Checkin == ticket.Checkin)
                               .AsNoTracking();
                }

                List <FlightTicket> ticketFind2 = await e_ticket.ToListAsync();

                List <Logic.FlightTicket> resultticket = ticketFind2.Select(Mapper.MapEToFlightTicket).ToList();
                if (resultticket.Count < 1)
                {
                    //logger.Warn();
                    return(null);
                }
                return(resultticket);
            }
            else
            {
                List <Logic.FlightTicket> ticketFind = new List <Logic.FlightTicket>
                {
                    Mapper.MapEToFlightTicket(dbcontext.FlightTicket.Find(ticket.TicketID))
                };
                //logger.Info();
                return(ticketFind);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(int id)
        {
            Logic.FlightTicket fli = new Logic.FlightTicket();
            fli.TicketID = id;

            await iRepo.DeleteFlightTicket(fli);

            return(Ok());
        }
Esempio n. 3
0
        public async Task <string> CreateFlightTicket(Logic.FlightTicket ticket)
        {
            FlightTicket e_ticket = Mapper.MapFlightTicketToE(ticket);

            dbcontext.Add(e_ticket);
            await dbcontext.SaveChangesAsync();

            //logger.info();
            return("New Ticket Created!");
        }
Esempio n. 4
0
        public async Task <ActionResult> Post([FromBody, Bind("FlightID, CustomerID, Price, CheckIn, Luggage")] API.Models.APIFlightTicket flightTicket)
        {
            Logic.FlightTicket flight = new Logic.FlightTicket
            {
                TicketID   = flightTicket.TicketID,
                FlightID   = flightTicket.FlightID,
                CustomerID = flightTicket.CustomerID,
                Price      = flightTicket.Price,
                Checkin    = flightTicket.CheckIn,
                Luggage    = flightTicket.Luggage
            };

            await iRepo.CheckSeatAvailible(flight.FlightID, 1);

            await iRepo.CreateFlightTicket(flight);

            return(CreatedAtRoute("GetFlightTicket", new { id = flight.TicketID }, flight));
        }
Esempio n. 5
0
        public async Task <string> DeleteFlightTicket(Logic.FlightTicket ticket)
        {
            FlightTicket e_ticket = await dbcontext.FlightTicket.FindAsync(ticket.TicketID);

            if (e_ticket == null)
            {
                //logger.Warn("FlightTicket not found.")
                return("no such ticket");
            }
            Flight e_flight = dbcontext.Flight.Find(e_ticket.FlightID);

            e_flight.SeatAvailable++;
            dbcontext.Remove(dbcontext.FlightTicket.Find(ticket.TicketID));

            await dbcontext.SaveChangesAsync();

            //logger.info();
            return("delete success");
        }
Esempio n. 6
0
        public async Task <IActionResult> Put([FromBody] API.Models.APIFlightTicket AflightTicket)
        {
            Logic.FlightTicket fli = new Logic.FlightTicket();

            IEnumerable <Logic.FlightTicket> LflightTickets = await iRepo.ReadTicketList(fli);

            Logic.FlightTicket newFli = new Logic.FlightTicket
            {
                TicketID   = AflightTicket.TicketID,
                FlightID   = AflightTicket.FlightID,
                CustomerID = AflightTicket.CustomerID,
                Price      = AflightTicket.Price,
                Checkin    = AflightTicket.CheckIn,
                Luggage    = AflightTicket.Luggage
            };

            await iRepo.UpdateFlightTicket(newFli);

            return(Ok());
        }
        public void MapEToTicketTest()
        {
            d.FlightTicket ticket1 = new d.FlightTicket
            {
                FlightTicketID = 1,
                CustomerID     = 1,
                FlightID       = 1,
                Checkin        = true,
                Price          = 123.55,
                Luggage        = 2
            };

            l.FlightTicket ticket2 = d.Mapper.MapEToFlightTicket(ticket1);

            Assert.Equal(ticket1.FlightTicketID, ticket2.TicketID);
            Assert.Equal(ticket1.CustomerID, ticket2.CustomerID);
            Assert.Equal(ticket1.FlightID, ticket2.FlightID);
            Assert.Equal(ticket1.Checkin, ticket2.Checkin);
            Assert.Equal(ticket1.Price, ticket2.Price);
            Assert.Equal(ticket1.Luggage, ticket2.Luggage);
        }
Esempio n. 8
0
        public async Task <IEnumerable <API.Models.APIFlightTicket> > Get(int id)
        {
            Logic.FlightTicket LTicket = new Logic.FlightTicket();
            LTicket.TicketID = id;

            //Be careful with int because default for int is 0 not null
            //Read maximum ID from database and pass it as parameter for If
            if (LTicket.TicketID <= 0 || LTicket.TicketID > await iRepo.GetTicketId())
            {
                IEnumerable <Logic.FlightTicket> allFlightTickets = await iRepo.ReadTicketList(null);

                IEnumerable <API.Models.APIFlightTicket> nullAPI = allFlightTickets.Select(af => new API.Models.APIFlightTicket
                {
                    TicketID   = af.TicketID,
                    FlightID   = af.FlightID,
                    CustomerID = af.CustomerID,
                    Price      = af.Price,
                    CheckIn    = af.Checkin,
                    Luggage    = af.Luggage
                });
                return(nullAPI);
            }

            IEnumerable <Logic.FlightTicket> flightTickets = await iRepo.ReadTicketList(LTicket);

            IEnumerable <API.Models.APIFlightTicket> apiFlightTicket = flightTickets.Select(ft => new API.Models.APIFlightTicket
            {
                //APIModel = Logic
                TicketID   = ft.TicketID,
                FlightID   = ft.FlightID,
                CustomerID = ft.CustomerID,
                Price      = ft.Price,
                CheckIn    = ft.Checkin,
                Luggage    = ft.Luggage
            });

            return(apiFlightTicket);
        }
Esempio n. 9
0
        public async Task <string> UpdateFlightTicket(Logic.FlightTicket ticket)
        {
            FlightTicket e_ticket = await dbcontext.FlightTicket.FindAsync(ticket.TicketID);

            if (e_ticket == null)
            {
                //logger.Warn("Airport not Found")
                return("no such Airport");
            }

            if (ticket.CustomerID > 0)
            {
                e_ticket.CustomerID = ticket.CustomerID;
            }
            if (ticket.FlightID > 0)
            {
                e_ticket.FlightID = ticket.FlightID;
            }
            if (ticket.Checkin != e_ticket.Checkin)
            {
                e_ticket.Checkin = ticket.Checkin;
            }
            if (ticket.Luggage > 0)
            {
                e_ticket.Luggage = ticket.Luggage;
            }
            if (ticket.Price > 0)
            {
                e_ticket.Price = ticket.Price;
            }

            await dbcontext.SaveChangesAsync();

            //logger.Info();

            return("update success");
        }