Exemplo n.º 1
0
 private void _updateOptionChoiceEntities(Booking booking)
 {
     foreach (OptionChoice optChoiceEntity in booking.OptionChoices)
     {
         OptionChoiceEntity optCEntity = new OptionChoiceEntity(booking, optChoiceEntity);
         _optionChoiceEntities.Add(optCEntity);
     }
 }
Exemplo n.º 2
0
        private bool _isChoosen(object item)
        {
            if (!(item is OptionChoiceEntity))
            {
                throw new InvalidOperationException("Seules les OptionChoiceEntity peuvent êtres filtrées (OptionsViewModel). Cette exception est critique.");
            }
            OptionChoiceEntity optChoiceEntity = item as OptionChoiceEntity;

            return(optChoiceEntity.Taken);
        }
Exemplo n.º 3
0
        private void _updateDates(OptionChoiceEntityChange optChoiceEntityChange, OptionChoiceEntity optChoiceEntity)
        {
            if (optChoiceEntityChange.Kind == OptionChangeKind.Taken && optChoiceEntity.Taken)
            {
                DateRange dateRange = (DateRange)((ICloneable)_booking.Dates).Clone();
                optChoiceEntity.TakenStart = dateRange.Start;
                optChoiceEntity.TakenEnd   = dateRange.End;

                if (optChoiceEntity.OptionChoice.Option.Id == 8)
                {
                    optChoiceEntity.TakenStart = dateRange.Start.Date.AddDays(1.0d);
                }
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        private void _optionsChanged(object sender, OptionChoiceEntityChange optChoiceEntityChange)
        {
            try
            {
                OptionChoiceEntity optChoiceEntity = optChoiceEntityChange.OptionChoiceEntity;
                int optChoiceIndex = _booking.OptionChoices.FindIndex(optC => optC.Option.Id == optChoiceEntity.OptionChoice.Option.Id);

                _updateDates(optChoiceEntityChange, optChoiceEntity);

                _updateOptionChoices(optChoiceEntityChange, optChoiceEntity, optChoiceIndex);

                RoomChoices.Update(optChoiceEntity);

                _unlockSearchClientAndNewClientIfNeeded();

                _checkCapacityWithBabies(optChoiceEntity);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Exemplo n.º 6
0
        private void _checkCapacityWithBabies(OptionChoiceEntity optChoiceEntity)
        {
            bool previouslyHadBabyRoom = hasAvailableBabyRoom();

            bool hasBabyRoom = hasAvailableBabyRoom();

            if (_parameters.BabiesCount > 0 && optChoiceEntity.Taken && previouslyHadBabyRoom)
            {
                if (!hasBabyRoom)
                {
                    MessageReceived?.Invoke(null, $"#Aucune chambre avec lit bébé ne possède l'option {optChoiceEntity.Description}!");
                }
                else
                {
                    MessageReceived?.Invoke(null, null);
                }
            }

            else if (_parameters.BabiesCount > 0 && hasBabyRoom && !previouslyHadBabyRoom)
            {
                MessageReceived?.Invoke(null, null);
            }
        }
Exemplo n.º 7
0
        private void _optionChanged(object sender, PropertyChangedEventArgs pcea)
        {
            try
            {
                if (!(sender is OptionChoiceEntity))
                {
                    throw new InvalidOperationException();
                }

                OptionChoiceEntity optChoiceEntity = sender as OptionChoiceEntity;
                OptionChangeKind   kind            = OptionChangeKind.Default;

                switch (pcea.PropertyName)
                {
                case nameof(optChoiceEntity.Taken):
                    kind = OptionChangeKind.Taken;
                    break;

                case nameof(optChoiceEntity.TakenStart):
                case nameof(optChoiceEntity.TakenEnd):
                    kind = OptionChangeKind.TakenDates;
                    break;

                case nameof(optChoiceEntity.PeopleCount):
                    kind = OptionChangeKind.PeopleCount;
                    break;
                }

                OptionChoiceEntityChange optChange = new OptionChoiceEntityChange(kind, optChoiceEntity);

                OptionChanged?.Invoke(null, optChange);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Exemplo n.º 8
0
 public OptionChoiceEntityChange(OptionChangeKind kind, OptionChoiceEntity optChoiceEntity)
 {
     Kind = kind;
     OptionChoiceEntity = optChoiceEntity;
 }
Exemplo n.º 9
0
        private void _updateOptionChoices(OptionChoiceEntityChange optChoiceEntityChange, OptionChoiceEntity optChoiceEntity, int optChoiceIndex)
        {
            if (optChoiceEntity.Taken && optChoiceEntityChange.Kind == OptionChangeKind.Taken)
            {
                if (optChoiceIndex != -1)
                {
                    _booking.OptionChoices.RemoveAt(optChoiceIndex);
                }
                _booking.OptionChoices.Add(optChoiceEntity.OptionChoice);
            }


            else if (!optChoiceEntity.Taken && optChoiceEntityChange.Kind == OptionChangeKind.Taken && optChoiceIndex != -1)
            {
                _booking.OptionChoices.Remove(optChoiceEntity.OptionChoice);
            }
        }
Exemplo n.º 10
0
        public void Update(OptionChoiceEntity optChoiceEntity)
        {
            Predicate <Room> missChoosenOpt = room => room.Options.FindIndex(opt => opt.Id == optChoiceEntity.OptionChoice.Option.Id) == -1;

            if (optChoiceEntity.Taken)
            {
                for (int i = _availableRooms.Count - 1; i >= 0; i--)
                {
                    if (missChoosenOpt(_availableRooms[i]))
                    {
                        _filteredRooms.Add(_availableRooms[i]);
                        _availableRoomCounts[_availableRooms[i].Kind]--;
                        _availableRooms.RemoveAt(i);
                    }
                }


                for (int i = _availableRoomChoiceEntities.Count - 1; i >= 0; i--)
                {
                    RoomKind roomKind = _availableRoomChoiceEntities[i].RoomKind;
                    if (_availableRoomCounts[roomKind] == 0)
                    {
                        _availableRoomChoiceEntities.RemoveAt(i);
                    }
                    else
                    {
                        _availableRoomChoiceEntities[i].MaxAvailable = _availableRoomCounts[roomKind];
                    }
                }
            }
            else
            {
                HashSet <RoomKind> newlyAvailableRoomKinds = new HashSet <RoomKind>();
                HashSet <RoomKind> extraRoomAvailableKinds = new HashSet <RoomKind>();

                for (int i = _filteredRooms.Count - 1; i >= 0; i--)
                {
                    if (missChoosenOpt(_filteredRooms[i]))
                    {
                        _availableRooms.Add(_filteredRooms[i]);
                        _availableRoomCounts[_filteredRooms[i].Kind]++;
                        if (_availableRoomCounts[_filteredRooms[i].Kind] == 1)
                        {
                            newlyAvailableRoomKinds.Add(_filteredRooms[i].Kind);
                        }
                        else
                        {
                            extraRoomAvailableKinds.Add(_filteredRooms[i].Kind);
                        }
                        _filteredRooms.RemoveAt(i);
                    }
                }

                foreach (RoomKind kind in newlyAvailableRoomKinds)
                {
                    RoomChoiceEntity roomChoiceEntity = new Entities.RoomChoiceEntity(kind, _availableRoomCounts[kind], 0);
                    _availableRoomChoiceEntities.Add(roomChoiceEntity);
                }

                foreach (RoomKind kind in extraRoomAvailableKinds)
                {
                    foreach (RoomChoiceEntity roomChoiceEntity in _availableRoomChoiceEntities)
                    {
                        if (roomChoiceEntity.RoomKind.Equals(kind))
                        {
                            roomChoiceEntity.MaxAvailable = _availableRoomCounts[kind];
                            break;
                        }
                    }
                }
            }
        }