public (bool, string, TrainOrder) BookTrainTicket(TrainShift TrainShift, TrainStation StartTrainStation, TrainStation EndTrainStation, IList <SeatTypeConfig> SeatTypes, CustomerInfo CustomerInfo, UserContract UserContract) { return(BookTrainTicket(TrainShift, StartTrainStation, EndTrainStation, SeatTypes, CustomerInfo, new List <UserContract>() { UserContract })); }
public void RemoveTrainStation(TrainStation TrainStation) { TrainStations.Remove(TrainStation); foreach (var item in TrainStations.Where(o => o.Order >= TrainStation.Order)) { item.SetOrder(item.Order - 1); } }
public void AddTrainStation(TrainStation TrainStation) { TrainStations.Add(TrainStation); foreach (var item in TrainStations.Where(o => o.Order >= TrainStation.Order)) { item.SetOrder(item.Order + 1); } }
public TrainOrder(TrainStation StartTrainStation, TrainStation EndTrainStation, CustomerInfo CustomerInfo, IList <TrainOrderItem> TrainOrderItems) : base() { this.OrderNo = GenerateOrderNoHelp.GenerateOrderNo(); this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; this.CustomerInfo = CustomerInfo; this.Status = OrderStatusType.PrePay; this.TrainOrderItems = TrainOrderItems; }
public TrainStationWay(TrainStation StartTrainStation, TrainStation EndTrainStation) { this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; AddTime = DateTimeOffset.Now; UpdateTime = DateTimeOffset.Now; AddUserId = UserHelper.User.Id; UpdateUserId = UserHelper.User.Id; }
public TrainTicketPrice(TrainStation StartTrainStation, TrainStation EndTrainStation, IList <TrainSeatPrice> TrainSeatPrices) { this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; this.TrainSeatPrices = TrainSeatPrices; AddTime = DateTimeOffset.Now; UpdateTime = DateTimeOffset.Now; AddUserId = UserHelper.User.Id; UpdateUserId = UserHelper.User.Id; }
public void RemoveTrainStation(TrainStation TrainStation) { if (TrainStation == null) { throw new NullReferenceException("TrainCarriage is not null"); } TrainStations.Remove(TrainStation); foreach (var item in TrainStations.Where(o => o.Order >= TrainStation.Order)) { item.SetOrder(item.Order - 1); } }
public void AddTrainStation(TrainStation TrainStation) { if (TrainStations == null) { TrainStations = new List <TrainStation>(); } TrainStations.Add(TrainStation); foreach (var item in TrainStations.Where(o => o.Order >= TrainStation.Order)) { item.SetOrder(item.Order + 1); } }
private static bool isEqual(TrainStation left, TrainStation right) { var a = ReferenceEquals(left, null); var b = ReferenceEquals(right, null); if (a ^ b) { return(false); } var c = ReferenceEquals(left, null); var d = left.Equals(right); return(c || d); }
public TrainOrder(TrainStation StartTrainStation, TrainStation EndTrainStation, CustomerInfo CustomerInfo, IList <TrainOrderItem> TrainOrderItems) { Id = Guid.NewGuid(); this.OrderNo = GenerateOrderNoHelp.GenerateOrderNo(); this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; this.CustomerInfo = CustomerInfo; this.Status = OrderStatusType.PrePay; this.TrainOrderItems = TrainOrderItems; AddTime = DateTimeOffset.Now; UpdateTime = DateTimeOffset.Now; AddUserId = UserHelper.User.Id; UpdateUserId = UserHelper.User.Id; }
private Seat isMatchSeat(TrainShift TrainShift, TrainStation StartTrainStation, TrainStation EndTrainStation, IList <SeatTypeConfig> SeatTypes) { foreach (var item in TrainShift.SaleSeatInfos.Select(o => o.DestinationSeat)) { int count = item.TrainStationWays.Count(o => (StartTrainStation <o.EndTrainStation && EndTrainStation> o.EndTrainStation) || (EndTrainStation > o.StartTrainStation && EndTrainStation < o.EndTrainStation) || (StartTrainStation >= o.StartTrainStation && EndTrainStation <= o.EndTrainStation) || (StartTrainStation <= o.StartTrainStation && EndTrainStation >= o.EndTrainStation) ); if (count == 0 && SeatTypes.Contains(item.Seat.SeatType)) { return(item.Seat); } } return(null); }
public TrainTicketPrice(TrainStation StartTrainStation, TrainStation EndTrainStation, IList <TrainSeatPrice> TrainSeatPrices = null) : base() { this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; this.TrainSeatPrices = TrainSeatPrices ?? new List <TrainSeatPrice>(); }
public TrainStationWay(TrainStation StartTrainStation, TrainStation EndTrainStation) : base() { this.StartTrainStation = StartTrainStation; this.EndTrainStation = EndTrainStation; }
public (bool, string, TrainOrder) BookTrainTicket(TrainShift TrainShift, TrainStation StartTrainStation, TrainStation EndTrainStation, IList <SeatTypeConfig> SeatTypes, CustomerInfo CustomerInfo, IList <UserContract> UserContracts) { if (StartTrainStation == null) { throw new ArgumentNullException("StartTrainStation"); } if (!StartTrainStation.IsSale) { throw new ArgumentNullException($"{StartTrainStation} is Not Sale"); } if (EndTrainStation == null) { throw new ArgumentNullException("EndTrainStation"); } if (SeatTypes == null) { throw new ArgumentNullException("SeatTypes"); } if (UserContracts == null || UserContracts.Count == 0) { throw new ArgumentNullException("UserContract"); } if (UserContracts.Count(o => o.UserType != ContractUserType.Children) == 0) { throw new Exception("儿童不能单独买票"); } if (StartTrainStation.Order > EndTrainStation.Order) { throw new ArgumentNullException("StartTrainStation same EndTrainStation Order"); } if (StartTrainStation.Order > EndTrainStation.Order) { var temp = StartTrainStation; StartTrainStation = EndTrainStation; EndTrainStation = temp; } var trainStationWay = new TrainStationWay(StartTrainStation, EndTrainStation); IList <Seat> seats = isMatchSeats(TrainShift, StartTrainStation, EndTrainStation, SeatTypes); //匹配优先在同一车厢 if (seats == null || seats.Count == 0) { seats = TrainShift.ExtraSeatInfos.Select(o => o.Seat).Where(o => SeatTypes.Contains(o.SeatType)).GroupBy(o => o.TrainCarriage).Where(o => o.Count() >= UserContracts.Count).FirstOrDefault().Take(UserContracts.Count).ToList(); if (seats == null) { seats = TrainShift.ExtraSeatInfos.Select(o => o.Seat).Where(o => SeatTypes.Contains(o.SeatType)).Take(UserContracts.Count).ToList(); if (seats == null || seats.Count < UserContracts.Count) { throw new Exception("余票不足,建议单独购买"); } } } else if (seats.Count < UserContracts.Count) { foreach (var item in seats) { seats = seats.Union(TrainShift.ExtraSeatInfos.Select(o => o.Seat).Where(o => SeatTypes.Contains(o.SeatType) && o.TrainCarriage == item.TrainCarriage).Take(UserContracts.Count - seats.Count).ToList()).ToList(); if (seats.Count == UserContracts.Count) { break; } } if (seats.Count < UserContracts.Count) { seats = seats.Union(TrainShift.ExtraSeatInfos.Select(o => o.Seat).Where(o => SeatTypes.Contains(o.SeatType)).Take(UserContracts.Count - seats.Count).ToList()).ToList(); if (seats.Count < UserContracts.Count) { throw new Exception("余票不足,建议单独购买"); } } } else { seats = seats.GroupBy(o => o.TrainCarriage).Where(o => o.Count() >= UserContracts.Count).FirstOrDefault().Take(UserContracts.Count).ToList(); if (seats == null || seats.Count == 0) { seats = seats.Take(UserContracts.Count).ToList(); } } if (seats == null || UserContracts.Count > seats.Count) { throw new Exception("余票不足"); } IList <TrainOrderItem> trainOrderItems = new List <TrainOrderItem>(); for (int i = 0; i < seats.Count; i++) { var seat = seats[i]; var userContract = UserContracts[i]; var b = TrainShift.ExtraSeatInfos.Remove(new ExtraSeatInfo(TrainShift, seat)); new FreezeSeatInfo(TrainShift, new DestinationSeat(seat, new List <TrainStationWay>() { trainStationWay })); new FreezeSeatInfo(TrainShift, new DestinationSeat(seat, new List <TrainStationWay>() { trainStationWay })); var price = TrainShift.TrainNumber.GetTrainStationWayPrice(trainStationWay, seat.SeatType); TrainOrderItem trainOrderItem = new TrainOrderItem(seat, userContract, price); trainOrderItems.Add(trainOrderItem); } TrainOrder trainOrder = new TrainOrder(trainStationWay.StartTrainStation, trainStationWay.EndTrainStation, CustomerInfo, trainOrderItems); return(true, "预定成功", trainOrder); }
public (bool, string, TrainOrder) BookTrainTicket(TrainShift TrainShift, TrainStation StartTrainStation, TrainStation EndTrainStation, SeatTypeConfig SeatType, CustomerInfo CustomerInfo, IList <UserContract> UserContracts) { return(BookTrainTicket(TrainShift, StartTrainStation, EndTrainStation, new List <SeatTypeConfig> { SeatType }, CustomerInfo, UserContracts)); }