Beispiel #1
0
        public BookingResponse SaveBookingStops(int bookingId, IEnumerable<BookingStop> stops)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    //remove
                    foreach (var stop in booking.Stops)
                        if (!stops.Any(s => s.Id == stop.Id))
                            stop.MarkAsDeleted();

                    //add
                    stops.Where(s => s.Id == 0)
                        .ForEach(s =>
                        {
                            s.ClearPropertiesButSkipKeys();
                            var newStop = new BookingStop();
                            newStop.SetDataFrom(s);
                            booking.Stops.Add(newStop);
                        });


                    //update
                    stops.Where(s => s.Id != 0).ForEach(s => booking.Stops.First(bs => bs.Id == s.Id).SetDataFrom(s));

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Beispiel #2
0
     public bool Equals(BookingStop other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.Id == 0 && Id == 0)
 			return false;
 		else
 			return other.Id == Id;
     }
 public BookingStopValidator(BookingStop endpoint)
 {
     _stop = endpoint;
 }
Beispiel #4
0
        private void OpenAddedStopsWindow(BookingStop stop, int index, bool isNew)
        {
            var viewModel = Kernel.Get<AddStopViewModel>();
            var view = Kernel.Get<AddStopWindow>();
            viewModel.City = CurrentBooking.City;
            viewModel.Stop = stop;
            viewModel.StopNumber = index + 1;
            view.DataContext = viewModel;

            viewModel.Completed += (o, e) =>
            {
                view.Close();
                if (isNew)
                {
                    AddedStops.Add(e.Value);
                }
                else
                {
                    AddedStops.RemoveAt(AddedStops.IndexOf(SelectedStop));
                    AddedStops.Insert(index, e.Value);
                }

                SelectedStop = e.Value;
            };

            view.Show();
        }
        public void SetDataFrom(BookingStop stop)
        {
            Clear();
            StopType = stop.StopType;
            if (stop.EndpointType == BookingEndpointType.Suburb)
            {
                EndpointType = BookingEndpointType.Suburb;
                LandmarkName = stop.LandmarkName;
                BuildingName = stop.BuildingName;
                Address1 = stop.Address1;
                Address2 = stop.Address2;
                SuburbId = stop.SuburbId;
            }
            else if (stop.EndpointType == BookingEndpointType.AirportPrivate)
            {
                EndpointType = BookingEndpointType.AirportPrivate;
                AirportId = stop.AirportId;
                Charter = stop.Charter;
                ArrivalOrDepartureTime = stop.ArrivalOrDepartureTime;
                OriginOrDestination = stop.OriginOrDestination;
            }
            else if (stop.EndpointType == BookingEndpointType.AirportOther)
            {
                EndpointType = BookingEndpointType.AirportOther;
                AirportId = stop.AirportId;
                AirlineId = stop.AirlineId;
                FlightNumber = stop.FlightNumber;
                ArrivalOrDepartureTime = stop.ArrivalOrDepartureTime;
                OriginOrDestination = stop.OriginOrDestination;
            }

            Info = stop.Info;
        }