Пример #1
0
 /// <summary>
 /// Removes the specified Room from the Zone collection of Rooms.
 /// </summary>
 /// <param name="room">The Room you want to remove.</param>
 public virtual void RemoveRoom(IRoom room)
 {
     if (Rooms.Contains(room))
     {
         Rooms.Remove(room);
     }
 }
 public bool RoomExists(string roomChosen)
 {
     if (Rooms != null && Rooms.Contains(roomChosen))
     {
         return(true);
     }
     return(false);
 }
Пример #3
0
 public T AddRoom <T>(T room) where T : Room
 {
     if (Rooms.Contains(room.ID))
     {
         throw new Exception("" + room + " already exists in ship " + ToString());
     }
     Rooms.Add(room);
     return(room);
 }
Пример #4
0
        private bool ChannelAddressesUs(ChannelBitField channel, ushort recipient)
        {
            if (channel.Type == ChannelType.Player)
            {
                return(recipient == _client.LocalId);
            }

            return(_rooms.Contains(recipient));
        }
Пример #5
0
 public bool ConnectsTo(Room _room)
 {
     if (Rooms.Contains(_room))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #6
0
        private void Check(Room from, Room to, List <Corridor> result, int width, int height)
        {
            if (to.Item1 < 0 || to.Item1 > width - 1 || to.Item2 < 0 || to.Item2 > height - 1)
            {
                return;
            }

            if (!Rooms.Contains(to))
            {
                result.Add(new Corridor(from.Item1, from.Item2, to.Item1, to.Item2));
            }
        }
Пример #7
0
 /// <summary>
 /// Removes a room from the job
 /// </summary>
 /// <param name="roomToDelete">The room that needs to be deleted</param>
 public void Remove(RoomVM roomToDelete)
 {
     if (MessageBox.Show("Deleting this room will delete all items contained in it. \nAre you sure you want to continue?",
                         "Warning",
                         MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         if (Rooms.Contains(roomToDelete))
         {
             Rooms.Remove(roomToDelete);
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Removes a slot from the database with the given roomname and bookingdate.
        /// </summary>
        /// <param name="roomName"></param>
        /// <param name="bookingDate"></param>
        /// <returns></returns>
        public Result RemoveSlot(string roomName, DateTime bookingDate)
        {
            // Check that the room exists
            if (!Rooms.Contains(roomName))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Room does not exist"
                });
            }

            // Check if the slot exists
            var slot = FindSlot(roomName, bookingDate);

            // If the slot does not exist we cannot remove it
            if (slot == null)
            {
                return(new Result {
                    Success = false, ErrorMsg = "The given slot does not exist"
                });
            }

            if (!String.IsNullOrEmpty(slot.StudentId))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Cannot remove a slot that a student has booked"
                });
            }

            var res = ExecuteSql("DELETE FROM [dbo].[Slot] WHERE " +
                                 $"[RoomID] = '{roomName}' AND " +
                                 $"[StartTime] = '{bookingDate.ToString(Model.SQLDateTimeFormat)}'");

            // If the SQL execs then remove the slot locally
            if (res)
            {
                Slots.Remove(slot);
                return(new Result {
                    Success = true
                });
            }

            return(new Result {
                Success = false, ErrorMsg = "Unable to execute database request"
            });
        }
Пример #9
0
        /// <summary>
        /// Adds a Room to the Zone. This is the preferred method for adding Rooms. It ensures that a null Room is never added to the collection
        /// as well as provides the ability to overwrite a Room if it already exists.
        /// </summary>
        /// <param name="room">The Room that you want to add to the Realm</param>
        /// <param name="forceOverwrite">If true, it will overwrite the Room if it already exists within the collection</param>
        public virtual void AddRoom(IRoom room, bool forceOverwrite = true)
        {
            if (room == null)
            {
                return;
            }

            if (forceOverwrite)
            {
                if (Rooms.Contains(room))
                {
                    Rooms.Remove(room);
                }
            }

            room.Zone = this;
            Rooms.Add(room);
        }
Пример #10
0
 public void MakeReservation(Lodger lodger, Room room, DateTime arrivalDate, DateTime departureDate)
 {
     AddLodger(lodger);
     if (Rooms.Contains(room))
     {
         if (Reservations.Where(r => r.HotelRoom.Equals(room) &&
                                ((r.ArrivalDate <= arrivalDate) && (r.DepartureDate >= arrivalDate) ||
                                 ((r.ArrivalDate <= departureDate) && (r.DepartureDate >= departureDate)) ||
                                 ((r.ArrivalDate >= arrivalDate) && (r.DepartureDate <= departureDate)))).Count() == 0)
         {
             Reservations.Add(new Reservation(lodger, room, arrivalDate, departureDate));
         }
         else
         {
             throw new RoomBusyException();
         }
     }
     else
     {
         throw new RoomNotFoundException();
     }
 }
Пример #11
0
        /// <summary>
        /// Cancels an existing booking.
        /// </summary>
        /// <param name="roomName">RoomID</param>
        /// <param name="bookingDate">Date/time of Booking</param>
        /// <returns></returns>
        public Result CancelBooking(string roomName, DateTime bookingDate)
        {
            if (!Rooms.Contains(roomName))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Room does not exist"
                });
            }

            var slot = FindSlot(roomName, bookingDate);

            // Check the slot exists before canceling the student booking.
            if (slot == null)
            {
                return(new Result {
                    Success = false, ErrorMsg = "Slot does not exist"
                });
            }

            var res = ExecuteSql("UPDATE [dbo].[Slot] SET" +
                                 "[BookedInStudentID] = null " +
                                 $"WHERE [RoomID] = '{roomName}' AND " +
                                 $"[StartTime] = '{bookingDate.ToString(Model.SQLDateTimeFormat)}'");

            if (res)
            {
                slot.StudentId = null;
                return(new Result {
                    Success = true
                });
            }

            return(new Result {
                Success = false, ErrorMsg = "Unable to execute database request"
            });
        }
Пример #12
0
 private bool IsAttached(Room room)
 {
     return(Rooms.Contains(room));
 }
Пример #13
0
 bool ICollection <IRecordedRoom> .Contains(IRecordedRoom item) => Rooms.Contains(item);
Пример #14
0
        protected virtual void SubscribeToEvents()
        {
            try
            {
                Proxy.On("userCreated", () =>
                {
                });

                Proxy.On <IEnumerable <dynamic> >("logOn", rooms =>
                {
                    foreach (var item in rooms)
                    {
                        string name = item.Name.Value;
                        long count  = item.Count.Value;
                        Rooms.Add(name);
                    }
                });

                Proxy.On <string, string, string>("sendPrivateMessage", (string arg1, string arg2, string arg3) =>
                {
                    var action = OnReceivePrivateMessage;

                    if (action != null)
                    {
                        action(arg1, arg2, arg3);
                    }
                });

                Proxy.On <dynamic, string>("addMessage", (dynamic arg1, string arg2) =>
                {
                    var action = OnReceiveRoomMessage;

                    if (action != null)
                    {
                        action(arg1, arg2);
                    }
                });

                Proxy.On <dynamic>("joinRoom", room =>
                {
                    string name = room.Name.Value;
                    long count  = room.Count.Value;
                    if (!Rooms.Contains(name.ToLower()))
                    {
                        Rooms.Add(name.ToLower());
                    }
                });

                Proxy.On <dynamic, string>("leave", (user, room) =>
                {
                    if (Rooms.Contains(room.ToLower()))
                    {
                        Rooms.Remove(room.ToLower());
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.ErrorException("An error occured while subscribing to events.", ex);;
            }
        }
Пример #15
0
        /// <summary>
        /// Creates a Slot with the given details within the database.
        /// </summary>
        /// <param name="roomName">Room ID</param>
        /// <param name="bookingDate">Date to create the slot</param>
        /// <param name="iD">Id of the booking member</param>
        /// <returns></returns>
        public Result CreateSlot(string roomName, DateTime bookingDate, string iD)
        {
            // Check room is exists.
            if (!Rooms.Contains(roomName))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Room does not exist"
                });
            }

            if (Slots.Count(x => x.StartTime.Date == bookingDate.Date && x.RoomName == roomName) >= 2)
            {
                return(new Result {
                    Success = false, ErrorMsg = "A room can be booked for a maximum of 2 slots per day"
                });
            }

            // Check slot does not already exist.
            if (FindSlot(roomName, bookingDate) != null)
            {
                return(new Result {
                    Success = false, ErrorMsg = "Slot already exists"
                });
            }

            // Check id exists.
            if (!GetStaff().Any(x => x.Id == iD))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Staff member does not exist"
                });
            }

            if (Slots.Count(x => x.StartTime.Date == bookingDate.Date && x.StaffId == iD) >= 4)
            {
                return(new Result {
                    Success = false, ErrorMsg = "Staff can be available for a maximum of 4 slots per day"
                });
            }

            // Create a slot.
            var newSlot = new Slot {
                RoomName = roomName, StartTime = bookingDate, StaffId = iD
            };

            // SQL to insert the new slot into the DB.
            bool res = ExecuteSql("INSERT INTO [dbo].[Slot] ([RoomID], [StartTime], [StaffID])" +
                                  "VALUES(" +
                                  $"(SELECT RoomID from [Room] where RoomID = '{newSlot.RoomName}')," +
                                  $"'{newSlot.StartTime.ToString(Model.SQLDateTimeFormat)}'," +
                                  $"(SELECT UserID from [User] where UserID = '{newSlot.StaffId}'))");

            if (res)
            {
                Slots.Add(newSlot);
                return(new Result {
                    Success = true
                });
            }
            return(new Result {
                Success = false, ErrorMsg = "Unable to execute database request"
            });
        }
Пример #16
0
 public bool IsInArea(DungeonRoom room)
 {
     return(Rooms.Contains(room));
 }
Пример #17
0
        /// <summary>
        /// Makes a booking on a valid slot
        /// </summary>
        /// <param name="roomName"></param>
        /// <param name="bookingDate"></param>
        /// <param name="iD"></param>
        /// <returns></returns>
        public Result MakeBooking(string roomName, DateTime bookingDate, string iD)
        {
            // Check that the room exists.
            if (!Rooms.Contains(roomName))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Room does not exist"
                });
            }

            // Check that the id exists.
            if (!GetStudents().Any(x => x.Id == iD))
            {
                return(new Result {
                    Success = false, ErrorMsg = "Student does not exist"
                });
            }

            // Check if a the student has already made a booking on this day
            if (Slots.Where(x => x.StartTime.Date == bookingDate.Date && x.StudentId == iD).Any())
            {
                return(new Result {
                    Success = false, ErrorMsg = "Student has already made a booking on this day"
                });
            }

            var slot = FindSlot(roomName, bookingDate);

            // Check the slot exists.
            if (slot == null)
            {
                return(new Result {
                    Success = false, ErrorMsg = "The given details do not match a slot"
                });
            }

            // Check the slot is not already booked.
            if (!string.IsNullOrEmpty(slot.StudentId))
            {
                return(new Result {
                    Success = false, ErrorMsg = "This slot is already booked"
                });
            }

            var res = ExecuteSql("UPDATE [dbo].[Slot] SET " +
                                 $"[BookedInStudentID] = (SELECT [User].[UserID] FROM [User] WHERE UserID = '{iD}') " +
                                 $"WHERE [RoomID] = '{roomName}' AND " +
                                 $"[StartTime] = '{bookingDate.ToString(Model.SQLDateTimeFormat)}'");

            // If the sql executes, update the local.
            if (res)
            {
                slot.StudentId = iD;
                return(new Result {
                    Success = true
                });
            }

            return(new Result {
                Success = false, ErrorMsg = "Unable to execute database request"
            });
        }