Пример #1
0
        public Protobuf.Trip ToPBMessage()
        {
            Protobuf.Trip tripPb = new Protobuf.Trip();
            tripPb.Id          = this.Id;
            tripPb.RouteId     = this.RouteId;
            tripPb.BusId       = this.BusId;
            tripPb.AvailSeats  = this.AvailSeats;
            tripPb.Date        = (int)Math.Floor(this.Date.ToUniversalTime().Subtract(DateTime.MinValue).TotalDays);
            tripPb.Time        = (int)Math.Floor(this.Time.TotalSeconds);
            tripPb.ArrivalDate = (int)Math.Floor(this.ArrivalDate.ToUniversalTime().Subtract(DateTime.MinValue).TotalDays);
            tripPb.ArrivalTime = (int)Math.Floor(this.ArrivalTime.TotalSeconds);

            tripPb.Bus   = this.Bus.ToPBMessage();
            tripPb.Route = this.Route.ToPBMessage();
            tripPb.Ticket.AddRange(this.Ticket.Select(t => t.ToPBMessage()));
            return(tripPb);
        }
Пример #2
0
        public Trip(Protobuf.Trip tripPb)
        {
            this.Id         = tripPb.Id;
            this.RouteId    = tripPb.RouteId;
            this.BusId      = tripPb.BusId;
            this.AvailSeats = tripPb.AvailSeats;
            DateTime temp = DateTime.MinValue.AddDays((double)tripPb.Date);

            temp             = temp.AddSeconds((double)tripPb.Time).ToLocalTime();
            this.Date        = temp.Date;
            this.Time        = temp.TimeOfDay;
            temp             = DateTime.MinValue.AddDays((double)tripPb.ArrivalDate);
            temp             = temp.AddSeconds((double)tripPb.ArrivalTime).ToLocalTime();
            this.ArrivalDate = temp.Date;
            this.ArrivalTime = temp.TimeOfDay;

            this.Bus    = new Bus(tripPb.Bus);
            this.Route  = new Route(tripPb.Route);
            this.Ticket = (HashSet <Ticket>)tripPb.Ticket.Select(t => new Ticket(t));
        }