Ejemplo n.º 1
0
        // Map TicketDbContext object to Ticket object
        public Ticket MapTicketDbToTicket(TicketDbContext TicketDB)
        {
            var RouteDAL = new RouteDAL();

            using (var db = new DB())
            {
                List <Passenger> TicketPassengers = new List <Passenger>();
                foreach (var Passenger in TicketDB.TicketPassengers)
                {
                    var OnePassenger = new Passenger
                    {
                        PassengerID   = Passenger.PassengerID,
                        PassengerType = Passenger.PassengerType
                    };
                    TicketPassengers.Add(OnePassenger);
                }
                var OneTicket = new Ticket
                {
                    TicketID           = TicketDB.TicketID,
                    TicketDuration     = TicketDB.TicketDuration,
                    TicketPrice        = TicketDB.TicketPrice,
                    TicketPurchaseDate = TicketDB.TicketPurchaseDate,
                    TicketPurchaseTime = TicketDB.TicketPurchaseTime,
                    OrderedBy          = TicketDB.OrderedBy,
                    StartStation       = TicketDB.StartStation,
                    EndStation         = TicketDB.EndStation,
                    TicketRoute        = RouteDAL.MapRouteDBToRoute(TicketDB.TicketRoute),
                    TicketPassengers   = TicketPassengers
                };
                return(OneTicket);
            }
        }
Ejemplo n.º 2
0
        // Map Ticket object to TicketDbContext object
        public TicketDbContext MapTicketToTicketDb(Ticket OneTicket)
        {
            var RouteDAL = new RouteDAL();

            using (var db = new DB())
            {
                List <PassengerDbContext> DBTicketPassengers = new List <PassengerDbContext>();
                foreach (var Passenger in OneTicket.TicketPassengers)
                {
                    var DBPassenger = new PassengerDbContext()
                    {
                        PassengerType = Passenger.PassengerType
                    };
                    DBTicketPassengers.Add(DBPassenger);
                }
                ;
                var OneRoute = db.Routes.Find(OneTicket.TicketRoute.RouteID);
                var DBTicket = new TicketDbContext()
                {
                    TicketDuration     = OneTicket.TicketDuration,
                    TicketPrice        = OneTicket.TicketPrice,
                    TicketPurchaseDate = OneTicket.TicketPurchaseDate,
                    TicketPurchaseTime = OneTicket.TicketPurchaseTime,
                    OrderedBy          = OneTicket.OrderedBy,
                    StartStation       = OneTicket.StartStation,
                    EndStation         = OneTicket.EndStation,
                    TicketPassengers   = DBTicketPassengers,
                    TicketRoute        = OneRoute
                };


                return(DBTicket);
            }
        }