Example #1
0
        public static async Task<RoomsChoiceViewModel> CreateAsync(DateRange dates)
        {
            RoomsChoiceViewModel newInstance = new RoomsChoiceViewModel();
            newInstance._availableRooms = await RoomRepository.GetAvailablesBetweenAsync(dates);

            int i = 0;
            foreach (Room room in newInstance._availableRooms)
            {
                if (!newInstance._availableRoomCounts.ContainsKey(room.Kind))
                {
                    newInstance._availableRoomCounts.Add(room.Kind, 1);
                    RoomChoiceEntity roomChoice = new RoomChoiceEntity(room.Kind, 0, 0);
                    newInstance._availableRoomChoiceEntities.Add(roomChoice);
                    i++;
                }
                else
                {
                    newInstance._availableRoomCounts[room.Kind]++;
                }
            }

            foreach (RoomChoiceEntity roomChoice in newInstance._availableRoomChoiceEntities)
            {
                roomChoice.MaxAvailable = newInstance._availableRoomCounts[roomChoice.RoomKind];
            }

            return newInstance;
        }
Example #2
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;
                        }
                    }
                }
            }
        }
Example #3
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;
                        }
                    }
                }
            }
        }