Beispiel #1
0
        public async Task <bool> CheckIn(int ticketId, string firstName, string lastName)
        {
            List <Customer> customers = await dbcontext.Customer.Where(c => c.FirstName == firstName &&
                                                                       c.LastName == lastName).AsNoTracking().ToListAsync();

            if (customers.Count < 1)
            {
                return(false);
            }
            else
            {
                foreach (Customer cus in customers)
                {
                    FlightTicket ticket = dbcontext.FlightTicket.Where(t => t.FlightTicketID == ticketId &&
                                                                       t.CustomerID == cus.CustomerID).AsNoTracking().First();
                    if (ticket == null)
                    {
                        return(false);
                    }
                }

                FlightTicket ticket1 = await dbcontext.FlightTicket.FindAsync(ticketId);

                ticket1.Checkin = true;

                await dbcontext.SaveChangesAsync();

                return(true);
            }
        }
Beispiel #2
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!");
        }
Beispiel #3
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");
        }
        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);
        }
Beispiel #5
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");
        }