Ejemplo n.º 1
0
 public PaymentEntity(Booking booking)
 {
     _pcs = new PropertyChangeSupport(this);
     _booking = booking;
     _requiredAmmount = booking.Total;
     _booking.Payment = booking.Payment;
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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));
         }
     }
 }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 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);
         }
     }
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        /// <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;
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
 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);
     }
 }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
        /// <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;
                    }
                }
            }
        }
Ejemplo n.º 17
0
 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);
     }
 }
Ejemplo n.º 18
0
 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);
         }
     }
 }
Ejemplo n.º 19
0
 private static async Task<Booking> _saveBooking(Booking booking, ResotelContext ctx, DbContextTransaction transaction)
 {
     await ctx.SaveChangesAsync();
     transaction.Commit();
     return booking;
 }
Ejemplo n.º 20
0
 private static void _replaceRoom(Booking booking, Room unavailableRoom, Room replacementRoom)
 {
     booking.Rooms.Add(replacementRoom);
     booking.Rooms.Remove(unavailableRoom);
 }
Ejemplo n.º 21
0
 private void _updateOptionChoiceEntities(Booking booking)
 {
     foreach (OptionChoice optChoiceEntity in booking.OptionChoices)
     {
         OptionChoiceEntity optCEntity = new OptionChoiceEntity(booking, optChoiceEntity);
         _optionChoiceEntities.Add(optCEntity);
     }
 }
Ejemplo n.º 22
0
 private static void _assignCtxRooms(Booking booking, List<Room> rooms)
 {
     booking.Rooms = rooms.FindAll(room => booking.Rooms.Any(r => r.Id == room.Id));
 }
Ejemplo n.º 23
0
 private static void _updateTrackedBooking(Booking trackedBooking, Booking booking, ResotelContext ctx)
 {
     
     ctx.Entry(trackedBooking).State = EntityState.Modified;
     ctx.Entry(trackedBooking).CurrentValues.SetValues(booking);
 }
Ejemplo n.º 24
0
        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);
            }
        }
Ejemplo n.º 25
0
        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);
            }
        }