public PaymentEntity(Booking booking) { _pcs = new PropertyChangeSupport(this); _booking = booking; _requiredAmmount = booking.Total; _booking.Payment = booking.Payment; }
public BookingEntity(Booking booking) { _pcs = new PropertyChangeSupport(this); _booking = booking; _clientEntity = new ClientEntity(_booking.Client); _paymentEntity = new PaymentEntity(booking); _datesEntity = new DateRangeEntity(_booking.Dates); _discountedOptionChoiceEntity = new OptionChoiceEntity(_booking, _booking.DiscountedOptionChoice); _optionDiscountEntity = new DiscountEntity(_booking.OptionDiscount); }
public BookedRoomEntity(Booking booking, Room room) { _room = room; _appliedPackEntities = new List<AppliedPackEntity>(); foreach(AppliedPack appliedPack in booking.RoomPacks) { if(appliedPack.Room.Id == _room.Id) { _appliedPackEntities.Add(new AppliedPackEntity(appliedPack)); } } }
/// <summary> /// Charge une liste d'options à partir d'options existantes d'une réservation. /// </summary> /// <param name="booking">réservation existante pour mémoire</param> /// <param name="dates">plage de date de la réservation</param> /// <returns></returns> public static async Task<OptionsViewModel> CreateAsync(Booking booking, DateRange dates) { OptionsViewModel newInstance = new OptionsViewModel(); List<Option> availableOptions = await OptionRepository.GetAvailablesBetweenAsync(dates); _setAvailableOptionChoiceEntities(booking, dates, newInstance, availableOptions); foreach (OptionChoiceEntity optChoiceEntity in newInstance._availableOptionChoiceEntities) { optChoiceEntity.PropertyChanged += newInstance._optionChanged; } return newInstance; }
public BookingParametersViewModel(Booking booking) { _pcs = new PropertyChangeSupport(this); _booking = booking; _booking.Dates.Start = booking.Dates.Start.Date; _booking.Dates.End = booking.Dates.End.Date; _dateRange = new DateRangeEntity(booking.Dates); _adultsCount = booking.AdultsCount; _babiesCount = booking.BabiesCount; _validateCommand = new DelegateCommand<object>(_validate); if(_adultsCount == 0 && booking.Id == 0) { AdultsCount = 1; } }
public OptionChoiceEntity(Booking booking, OptionChoice optionChoice) { _pcs = new PropertyChangeSupport(this); _optionChoice = optionChoice; _booking = booking; string cleanedLabel; if (optionChoice != null) { cleanedLabel = _cleanLabel(optionChoice.Option.Label); _imageFullPath = string.Format("/Resources/{0}.png", cleanedLabel); // restauration if(optionChoice.PeopleCount == 0 && optionChoice.Option.Id == 8) { PeopleCount = 1; } } _taken = false; }
private void _fillAppliedPacksEntities(Booking booking) { foreach (Room room in booking.Rooms) { BookedRoomEntity bookedRoomEntity = new BookedRoomEntity(booking, room); foreach (AppliedPackEntity appliedPackEntity in bookedRoomEntity.AppliedPackEntities) { _appliedPackEntities.Add(appliedPackEntity); } } }
public SumUpViewModel(LinkedList<INavigableViewModel> navigation, Booking booking, LinkedListNode<INavigableViewModel> prevNode = null) { _pcs = new PropertyChangeSupport(this); _navigation = navigation; _booking = booking; _dates = booking.Dates; _clientEntity = new ClientEntity(booking.Client); _paymentEntity = new PaymentEntity(booking); _paymentEntity.PropertyChanged += _payment_changed; _hasPayment = _booking.Payment != null && _booking.Payment.Ammount > 0d; _hadPayment = _hasPayment; _wasInTempState = _booking.State == BookingState.Validated; _appliedPackEntities = new List<AppliedPackEntity>(); _optionChoiceEntities = new List<OptionChoiceEntity>(booking.OptionChoices.Count); _updateOptionChoiceEntities(booking); _title = $"Réservation de {_clientEntity.FirstName} {_clientEntity.LastName} du {booking.Dates.Start:dd/MM/yyyy}"; _fillAppliedPacksEntities(booking); bool canSave = _booking.State == BookingState.Validated; _defineCommands(canSave); _definePaymentModes(); _unlockSaveIfNeeded(); _unlockEditIfNeeded(); if ((_booking.State != BookingState.Validated && canSave) || (_booking.State == BookingState.Validated && !canSave) ) { _saveBookingCommand.ChangeCanExecute(); } if (prevNode != null) { _navigation.AddAfter(prevNode, this); } else { _navigation.AddLast(this); } }
private void _addBooking(object ignore) { try { Logger.Log("=Ajout d'une réservation="); Booking booking = new Booking(); booking.CreationDate = DateTime.Now; booking.Dates.Start = DateTime.Now; booking.Dates.End = DateTime.Now.AddDays(1.0); Logger.Log("Ajout d'une réservation: chargement de la fiche de réservation"); BookingViewModel bookingVM = new BookingViewModel(_navigation, booking); _navigation = bookingVM.Navigation; _currentEntities.Add(bookingVM); _currentEntitiesView.MoveCurrentToPosition(_currentEntities.Count - 1); bookingVM.NextCalled += _nextCalled; bookingVM.PreviousCalled += _prevCalled; bookingVM.MessageReceived += _messageReceived; } catch (Exception ex) { Logger.Log(ex); } }
private static async Task _updateRoomPacks(Booking trackedBooking, IList<AppliedPack> trackedRoomPacks, IList<AppliedPack> newRoomPacks, ResotelContext ctx) { trackedRoomPacks.Clear(); foreach (AppliedPack appliedPack in newRoomPacks) { AppliedPack trackedAppliedPack = await ctx.Set<AppliedPack>().FirstOrDefaultAsync(ap => ap.Id == appliedPack.Id); if (trackedAppliedPack == null) { trackedAppliedPack = ctx.Set<AppliedPack>().Add(appliedPack); } Room trackedRoom = await ctx.Rooms.FirstOrDefaultAsync(r => r.Id == appliedPack.Room.Id); Pack trackedPack = await ctx.Set<Pack>().FirstOrDefaultAsync(p => p.Id == appliedPack.RoomPack.Id); trackedAppliedPack.Room = trackedRoom; trackedAppliedPack.RoomPack = trackedPack; trackedAppliedPack.Booking = trackedBooking; } }
public BookingViewModel(LinkedList<INavigableViewModel> navigation, Booking booking, LinkedListNode<INavigableViewModel> prevNode = null) { _pcs = new PropertyChangeSupport(this); _navigation = navigation; _parameters = new BookingParametersViewModel(booking); _parameters.Defined += _parameters_defined; _parameters.PropertyChanged += _parametersChanged; _parametersValidated = false; _booking = booking; _clientEntity = new ClientEntity(_booking.Client); _bookingEntity = new BookingEntity(_booking); _clientEntity.Bookings.Add(_bookingEntity); _computeTitle(_clientEntity); _clientEntity.PropertyChanged += _clientChanged; _searchClientCommand = new DelegateCommandAsync<BookingViewModel>(_searchClient, false); _newClientCommand = new DelegateCommandAsync<BookingViewModel>(_newClient, false); _validateBookingCommand = new DelegateCommandAsync<BookingViewModel>(_validateBooking, false); if (prevNode == null) { _navigation.AddLast(this); } else { _navigation.AddAfter(prevNode, this); } }
/// <summary> /// Loads a BookingViewModel from an existing Booking /// </summary> /// <param name="navigation">Navigation object used in MainViewWindow to change tab's content</param> /// <param name="booking">the existing booking loaded from db</param> /// <param name="prevNode">the reviously loaded INavigableViewModel, for use within navigation</param> /// <returns></returns> public static async Task<BookingViewModel> LoadAsync(LinkedList<INavigableViewModel> navigation, Booking booking, LinkedListNode<INavigableViewModel> prevNode) { BookingViewModel bookingVM = new BookingViewModel(navigation, booking, prevNode); await bookingVM._validateParameters(); return bookingVM; }
private static async Task<List<Room>> _replaceRooms(Booking booking, ResotelContext ctx, List<Room> unavailableRooms) { List<Room> unavailableReplacementRooms = new List<Room>(); foreach (Room unavailableRoom in unavailableRooms) { Room replacementRoom = await _getReplacementRoom(ctx, unavailableRoom); if (replacementRoom != null) { _replaceRoom(booking, unavailableRoom, replacementRoom); } else { unavailableReplacementRooms.Add(unavailableRoom); } } return unavailableReplacementRooms; }
private static async Task _updateBookingRooms(Booking trackedBooking, IList<Room> newRooms, ResotelContext ctx) { ctx.Entry(trackedBooking).Collection(b => b.Rooms).EntityEntry.State = EntityState.Modified; trackedBooking.Rooms.Clear(); foreach (Room room in newRooms) { Room trackedRoom = await ctx.Rooms.FirstOrDefaultAsync(r => r.Id == room.Id); trackedBooking.Rooms.Add(trackedRoom); } }
private static void _updateTrackedBookingState(Booking trackedBooking, BookingState newBookingState, ResotelContext ctx) { ctx.Entry(trackedBooking).Property( b => b.State).EntityEntry.State = EntityState.Modified; ctx.Entry(trackedBooking).Property(b => b.State).EntityEntry.CurrentValues.SetValues(newBookingState); }
/// <summary> /// SaveOrUpdate given Booking /// </summary> /// <param name="booking"></param> /// <returns>The saved booking, with its new id, if a new booking (which was never saved) is passed</returns> public async static Task<Booking> Save(Booking booking) { using (ResotelContext ctx = new ResotelContext()) { Booking savedBooking = null; List<Room> rooms = await _getRoomRequest(ctx, true) .ToListAsync(); List<Option> options = await _getOptionRequest(ctx) .ToListAsync(); Client client = await _getClientRequest(ctx).FirstOrDefaultAsync( cl => cl.Id == booking.Client.Id ); _assignCtxRooms(booking, rooms); _assignCtxOptions(booking, options); if (client != null) { booking.Client = client; } if (booking.Id == 0) { ctx.Entry(booking).State = EntityState.Added; } else { Booking trackedBooking = await ctx.Bookings.FirstOrDefaultAsync(b => b.Id == booking.Id); _updateTrackedBooking(trackedBooking, booking, ctx); await _updateOptionChoices(trackedBooking.OptionChoices, booking.OptionChoices, ctx); await _updateBookingRooms(trackedBooking, booking.Rooms, ctx); await _updateRoomPacks(trackedBooking, trackedBooking.RoomPacks, booking.RoomPacks, ctx); _updateTrackedBookingState(trackedBooking, booking.State, ctx); DateRange trackedBookingDates = await _getTrackedBookingDates(booking.Dates, ctx); trackedBooking.Dates = trackedBookingDates; } List<Room> unavailableRooms = new List<Room>(); using (DbContextTransaction transaction = ctx.Database.BeginTransaction()) { try { await _fillUnavailableRooms(booking, ctx, unavailableRooms); if (unavailableRooms.Count == 0) { savedBooking = await _saveBooking(booking, ctx, transaction); } else { List<Room> unavailableReplacementRooms = await _replaceRooms(booking, ctx, unavailableRooms); if (unavailableReplacementRooms.Count > 0) { HashSet<RoomKind> unreplaceableRoomKinds = new HashSet<RoomKind>(unavailableReplacementRooms.ConvertAll(room => room.Kind)); transaction.Rollback(); throw new InvalidOperationException( $"Impossible de sauvegarder la réservation : nous n'avons plus assez de chambres des types {string.Join(",", unreplaceableRoomKinds)}"); } else { savedBooking = await _saveBooking(booking, ctx, transaction); } } return savedBooking; } catch (Exception) { transaction.Rollback(); throw; } } } }
private static void _assignCtxOptions(Booking booking, List<Option> options) { foreach (OptionChoice optChoice in booking.OptionChoices) { optChoice.Option = options.Find(opt => optChoice.Option.Id == opt.Id); } }
private static async Task _fillUnavailableRooms(Booking booking, ResotelContext ctx, List<Room> unavailableRooms) { foreach (Room room in booking.Rooms) { Room freshRoom = await _getFreshRoom(ctx, room.Id); if (freshRoom == null) { unavailableRooms.Add(freshRoom); } } }
private static async Task<Booking> _saveBooking(Booking booking, ResotelContext ctx, DbContextTransaction transaction) { await ctx.SaveChangesAsync(); transaction.Commit(); return booking; }
private static void _replaceRoom(Booking booking, Room unavailableRoom, Room replacementRoom) { booking.Rooms.Add(replacementRoom); booking.Rooms.Remove(unavailableRoom); }
private void _updateOptionChoiceEntities(Booking booking) { foreach (OptionChoice optChoiceEntity in booking.OptionChoices) { OptionChoiceEntity optCEntity = new OptionChoiceEntity(booking, optChoiceEntity); _optionChoiceEntities.Add(optCEntity); } }
private static void _assignCtxRooms(Booking booking, List<Room> rooms) { booking.Rooms = rooms.FindAll(room => booking.Rooms.Any(r => r.Id == room.Id)); }
private static void _updateTrackedBooking(Booking trackedBooking, Booking booking, ResotelContext ctx) { ctx.Entry(trackedBooking).State = EntityState.Modified; ctx.Entry(trackedBooking).CurrentValues.SetValues(booking); }
private static void _setAvailableOptionChoiceEntities(Booking booking, DateRange dates, OptionsViewModel newInstance, List<Option> availableOptions) { foreach (Option opt in availableOptions) { OptionChoice optChoice = new OptionChoice { Option = opt, TakenDates = (DateRange)((ICloneable)dates).Clone() }; optChoice.TakenDates.Start = optChoice.TakenDates.Start.Date; if (optChoice.Option.Id == 8) { optChoice.TakenDates.Start = optChoice.TakenDates.Start.AddDays(1.0d); } OptionChoiceEntity optChoiceEntity = new OptionChoiceEntity(booking, optChoice); newInstance._availableOptionChoiceEntities.Add(optChoiceEntity); } }
private async Task _assignRooms(Booking booking) { try { List<Option> choosenOptions = booking.OptionChoices.ConvertAll(optChoice => optChoice.Option); List<Room> matchingRooms = await RoomRepository.GetMatchingRoomsBetween(choosenOptions, booking.Dates); booking.Rooms.Clear(); foreach (RoomChoiceEntity roomChoice in _availableRoomChoiceEntities) { if (roomChoice.Count > 0) { IList<Room> rooms = _findRooms(matchingRooms, roomChoice.BedKind, roomChoice.Count); if (rooms.Count > 0) { matchingRooms.RemoveAll(matchingRoom => booking.Rooms.FindIndex(room => room.Id == matchingRoom.Id) != -1); booking.Rooms.AddRange(rooms); } } } } catch (Exception ex) { Logger.Log(ex); } }