public ActionResult <RoomInfoDto> Get([ModelBinder(typeof(SimpleDateTimeModelBinder))] DateTime date, long id)
        {
            if (date < DateTime.Today)
            {
                return(BadRequest());
            }

            Room room = _roomRepository.GetById(id);

            if (room == null)
            {
                return(NotFound());
            }

            var unavailableDates = _reservationRepository.GetUnavailableDates(room.Id, date);

            RoomInfoDto dto = new RoomInfoDto();

            dto.Room           = room;
            dto.AvailableTimes = _reservationService.GetReservationDateTimes(
                date.Date.AddHours(room.OpenFrom),
                date.Date.AddHours(room.OpenTo),
                unavailableDates);

            return(Ok(dto));
        }
        public ActionResult <IEnumerable <RoomInfoDto> > Get([ModelBinder(typeof(SimpleDateTimeModelBinder))] DateTime date)
        {
            if (date < DateTime.Today)
            {
                return(BadRequest());
            }

            IEnumerable <Room> rooms = _roomRepository.GetAllWithReservations();

            List <RoomInfoDto> dtoList = new List <RoomInfoDto>();

            foreach (var room in rooms)
            {
                RoomInfoDto dto = new RoomInfoDto();
                dto.Room           = room;
                dto.AvailableTimes = _reservationService.GetReservationDateTimes(
                    date.Date.AddHours(room.OpenFrom),
                    date.Date.AddHours(room.OpenTo),
                    room.Reservations?.Select(x => x.ReservedFrom));
                //Do not include reservations in the DTO
                dto.Room.Reservations = null;

                dtoList.Add(dto);
            }

            return(Ok(dtoList));
        }
        /// <summary>
        /// 处理客户端对象离开房间的请求
        /// </summary>
        /// <param name="clientPeer">离开房间的客户端连接对象</param>
        /// <param name="roomId">要离开的房间编号</param>
        private void ProcessLeaveRoomRequest(ClientPeer clientPeer, int roomId)
        {
            #region 移除一些跟客户端对象引用相关的东东
            //需要断开要移除的客户端连接对象所有的引用指针(防止程序出现不正常的现象)
            this.passeServiceCache.RemoveUserScoreofUserScoreDict(clientPeer, roomId); //通过帕斯业务缓存对象从用户积分字典中移除指定地客户端连接对象
            this.passeServiceCache.SubClientPeer(clientPeer);                          //通过帕斯业务对象从客户端连接对象列表中移除客户端连接对象
            //Todo:中间可能还有其他模块部分需要移除客户端连接对象的引用指针
            //最后才需要从当前玩家要离开的房间中移除客户端对象
            RoomInfo tmpRoom = this.roomCache.LeaveRoom(clientPeer, roomId);
            //从房间中移除以后,需要广播消息给其他还在房间内的客户端对象,通知他们哪个玩家离开了房间
            //广播消息给其他客户端对象之后,需要将当前的房间数据重新广播给每一个在房间内的客户端对象
            #endregion

            #region 构建要传输的数据房间对象并把客户端需要的数据发送过去
            //构建房间信息传输数据对象(用于服务端把房间数据传输给客户端)
            RoomInfoDto roomInfoDto = new RoomInfoDto()
            {
                Id           = tmpRoom.Id,
                Name         = tmpRoom.Name,
                PersonNumber = tmpRoom.PersonNumber
            };
            //循环遍历房间内的客户端用户对象列表
            for (int userIndex = 0; userIndex < tmpRoom.UserInfos.Count; userIndex++)
            {
                UserInfo userInfo = tmpRoom.UserInfos[userIndex]; //取得当前循环遍历到的客户端用户对象数据
                                                                  //构建一个用户信息传输数据添加至房间信息数据传输对象的用户列表中
                roomInfoDto.Users.Add(
                    new UserInfoDto()
                {
                    Id          = userInfo.Id,
                    UserName    = userInfo.UserName,
                    Money       = userInfo.Money,
                    ClientIndex = tmpRoom.PersonNumber + 1
                });
            }
            #endregion

            #region 构造网络消息对象 广播给房间内的每一个客户端对象 和 当前要离开房间的客户端对象
            //构造服务端发送给客户端的网络消息对象
            this.message.ChangeMessage(OperationCode.Room, (int)RoomCode.LeaveRoom_BroadcastResponse, roomInfoDto);
            this.ProcessBroadcastMessage(clientPeer, roomId, this.message);
            #endregion

            #region 给房主广播一条空数据(没有实际作用,只是为了房主的数据同步工作,不会影响其他客户端对象)
            RoomInfo          tmpRoomInfo = this.roomCache.RoomIdRooms[tmpRoom.Id];      //获取房间信息对象
            List <ClientPeer> clients     = this.roomCache.RoomClientsDict[tmpRoomInfo]; //通过房间信息对象获取该房间内的客户端用户列表
            if (clients != null)                                                         //如果不为空的情况下
                                                                                         //默认给房主发送一个null数据(之前不这样做,会导致房主的数据不进行同步处理,出现了Bug,之后这样做,竟然神奇地解决了)
            {
                clients[0].OnSendMessage(
                    new SocketMessage()
                {
                    OperationCode    = OperationCode.Service,
                    SubOperationCode = (int)ServiceCode.Passe_Response,
                    DataValue        = "null"
                });
            }
            #endregion
        }//离开房间
Exemple #4
0
        public void TestGetRoomInfoWithIdOne()
        {
            DateTime            now      = DateTime.Today;
            HttpResponseMessage response = _client.GetAsync($"/api/rooms/{now.Day}.{now.Month}.{now.Year}/1").Result;

            response.EnsureSuccessStatusCode();

            RoomInfoDto roomInfoDto = response.Content.ReadAsAsync <RoomInfoDto>().Result;

            List <Room> rooms = TestDbInitializer.GetTestRooms();

            Assert.IsTrue(rooms.FirstOrDefault(r => r.Id == 1)?.Name == roomInfoDto.Room.Name);
        }
Exemple #5
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            RoomState state = (RoomState)parameter;

            // если значение и параметр == null, то блок не создается
            if (values == null || values[0] == null)
            {
                return(Visibility.Collapsed);
            }
            else
            {
                // получаем переданное значение
                RoomInfoDto roomInfoDto = values[0] as RoomInfoDto;
                // сопоставляем параметр и переданное значение
                switch (state)
                {
                case RoomState.Free:
                    if (roomInfoDto.ReserveStart == default && roomInfoDto.ReserveEnd == default)
                    {
                        return(Visibility.Visible);
                    }
                    else
                    {
                        return(Visibility.Collapsed);
                    }

                case RoomState.Reserved:
                    if (roomInfoDto.ReserveStart != default && roomInfoDto.ReserveEnd != default)
                    {
                        if (roomInfoDto.Clients == null || roomInfoDto.Clients.Count() == 0)
                        {
                            return(Visibility.Visible);
                        }
                        else
                        {
                            return(Visibility.Collapsed);
                        }
                    }
                    else
                    {
                        return(Visibility.Collapsed);
                    }

                case RoomState.Populated:
                    if (roomInfoDto.ReserveStart != default && roomInfoDto.ReserveEnd != default)
                    {
                        if (roomInfoDto.Clients != null && roomInfoDto.Clients.Count() != 0)
                        {
                            return(Visibility.Visible);
                        }
                        else
                        {
                            return(Visibility.Collapsed);
                        }
                    }
                    else
                    {
                        return(Visibility.Collapsed);
                    }

                default:
                    // по умолчанию не показываем
                    return(Visibility.Collapsed);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// 构造房间及客人详细信息
        /// </summary>
        /// <param name="sysCodeList"></param>
        /// <param name="roomCodeList"></param>
        /// <param name="guestAccList"></param>
        /// <param name="guestList"></param>
        /// <param name="bookingList"></param>
        /// <returns></returns>
        private List <RoomInfoDto> BuildRoomList(List <SystemCodeInfo> sysCodeList, List <RoomSymbolInfo> roomCodeList, List <GuestAccountingInfo> guestAccList, List <GuestDataInfo> guestList, List <GuestDataInfo> bookingList)
        {
            List <RoomInfoDto> roomInfoList = new List <RoomInfoDto>();

            #region 遍历生成房间及客人信息
            foreach (var room in roomCodeList)
            {
                var         guest        = guestList.Where(x => x.RoomNo == room.RoomNo).FirstOrDefault();   //获取当前在住房客人信息
                var         bookingGuest = bookingList.Where(x => x.RoomNo == room.RoomNo).FirstOrDefault(); //今日预低客人信息
                RoomInfoDto roomInfo     = new RoomInfoDto();

                roomInfo.RoomId       = room.RoomNo;
                roomInfo.GalleryCode  = room.GalleryCode;
                roomInfo.FloorCode    = room.FloorCode;
                roomInfo.RoomTypeCode = room.RoomTypeCode;
                roomInfo.Price        = room.Price;
                roomInfo.Status       = room.Status;
                roomInfo.IsClean      = room.IsClean;
                roomInfo.RoomState    = room.RoomState;
                roomInfo.RoomTypeName = sysCodeList.Where(x => x.SysCodeType == SystemCodeTypes.ROOM_CATEGORY && x.SysCode == room.RoomTypeCode).Select(x => x.SysCodeName).FirstOrDefault();

                roomInfo.GalleryName = sysCodeList.Where(x => x.SysCodeType == SystemCodeTypes.ROOM_GALLERY_CODE && x.SysCode == room.GalleryCode).Select(x => x.SysCodeName).FirstOrDefault();

                roomInfo.FloorName = sysCodeList.Where(x => x.SysCodeType == SystemCodeTypes.ROOM_FLOOR_CODE && x.SysCode == room.FloorCode).Select(x => x.SysCodeName).FirstOrDefault();

                //在住客人信息
                if (guest != null)
                {
                    roomInfo.GuestId     = guest.Id;
                    roomInfo.PayBillId   = guest.PayBillId;
                    roomInfo.ChummageId  = guest.ChummageId;
                    roomInfo.LinkRoomId  = guest.LinkRoomId;
                    roomInfo.ChineseName = guest.ChineseName;

                    roomInfo.IsVIP        = guest.VipType;
                    roomInfo.CheckInDate  = guest.CheckInDate;
                    roomInfo.CheckInTime  = guest.CheckInTime;
                    roomInfo.CheckOutDate = guest.CheckOutDate;
                    roomInfo.GuestRemark  = guest.GuestRemark;
                    //roomDto.Remark1 = "";
                    roomInfo.Phone             = guest.Phone;
                    roomInfo.RoomPriceCategory = guest.RoomPriceCategory;
                    //roomDto.Breakfast = room.Fhdmft00.Trim();
                    roomInfo.PayBillMethod         = guest.PayBillMethod.Trim();
                    roomInfo.RoomPriceCategoryName = roomInfo.RoomPriceCategory;
                    //roomData.MsgTitle = new BKrlyService().GetKrlyTitileByZh(roomData.krzh);
                    //roomData.MsgText = new BKrlyService().GetKrlyTextByZh(roomData.krzh);
                    roomInfo.GuestCategory = guest.GuestCategory.Trim();
                }

                if (bookingGuest != null)
                {
                    roomInfo.BookingNo           = bookingGuest.BookingId;
                    roomInfo.BookingGuestName    = bookingGuest.ChineseName;
                    roomInfo.BookingCheckInDate  = bookingGuest.CheckInDate;
                    roomInfo.BookingCheckOutDate = bookingGuest.CheckOutDate;
                    roomInfo.BookingPhone        = bookingGuest.Phone;
                    roomInfo.BookingRemark       = bookingGuest.GuestRemark;
                }

                if (guest != null && guest.Id > 0)
                {
                    roomInfo.Gender = guest.Gender == GenderDescTypes.Female ? GenderDescTypes.Female.GetDescription(typeof(GenderDescTypes), "Female") : GenderDescTypes.Male.GetDescription(typeof(GenderDescTypes), "Male");

                    //总消费
                    var totalAmount = guestAccList.Where(x => x.GuestId == guest.Id && x.BillType == PayBillTypes.C && x.AccountingType != GuestAccType.X && x.AccountingType != GuestAccType.H && x.AccountingType != GuestAccType.Y && x.Operation.IsEmpty() && x.CalculateAmount != 0 && x.AccId02 == 0).Select(x => x.CalculateAmount).Sum();

                    //总付款
                    var totalPayment = guestAccList.Where(x => x.GuestId == guest.Id && x.BillType == PayBillTypes.D && (x.AccountingType == GuestAccType.A || x.AccountingType == GuestAccType.H || x.AccountingType == GuestAccType.Z) && x.Status != AccStateSign.H).Select(x => x.CalculateAmount).Sum();

                    roomInfo.TotalAmount  = totalAmount.ToDecimal();
                    roomInfo.TotalPayment = totalPayment.ToDecimal();
                }
                else
                {
                    roomInfo.Gender       = "";
                    roomInfo.TotalAmount  = 0;
                    roomInfo.TotalPayment = 0;
                }
                roomInfo.Balance = roomInfo.TotalPayment - roomInfo.TotalAmount;

                roomInfoList.Add(roomInfo);
            }
            #endregion

            return(roomInfoList);
        }
        /// <summary>
        /// 进入房间
        /// </summary>
        /// <param name="clientPeer">进入房间的客户端对象</param>
        /// <param name="tmpRoom">要进入的房间</param>
        private void EnterRoom(ClientPeer clientPeer, RoomInfo tmpRoom)
        {
            tmpRoom.PersonNumber++;//累加房间人数
            LogMessage.Instance.SetLogMessage(
                string.Format("客户端对象IP地址为 [ {0} ] 的用户加入了一个房间编号为 [ {1} ] 的房间,这个房间的进入码为 [ {2} ]~", clientPeer.ClientSocket.RemoteEndPoint.ToString(), tmpRoom.Id.ToString(), tmpRoom.EnterCode.ToString()));
            #region 构建要传输的数据房间对象并把客户端需要的数据发送过去
            int currentClientIndex = this.roomCache.GetRoomClientIndexByRoomId(clientPeer, tmpRoom.Id);

            #region 通知客户端所在房间的座位号
            //通知客户端 你所在的房间中的座位号是
            clientPeer.OnSendMessage(new SocketMessage()
            {
                OperationCode    = OperationCode.Message,
                SubOperationCode = (int)MessageCode.SingleMessage,
                DataValue        = currentClientIndex.ToString()
            });
            #endregion

            //构建房间信息传输数据对象(用于服务端把房间数据传输给客户端)
            RoomInfoDto roomInfoDto = new RoomInfoDto()
            {
                Id           = tmpRoom.Id,
                Name         = tmpRoom.Name,
                PersonNumber = tmpRoom.PersonNumber,
                ServiceType  = (RoomInfoDto.RoomGameServiceType)tmpRoom.ServiceType
            };
            //循环遍历房间内的客户端用户对象列表
            for (int userIndex = 0; userIndex < tmpRoom.UserInfos.Count; userIndex++)
            {
                UserInfo userInfo = tmpRoom.UserInfos[userIndex]; //取得当前循环遍历到的客户端用户对象数据
                                                                  //构建一个用户信息传输数据添加至房间信息数据传输对象的用户列表中
                roomInfoDto.Users.Add(new UserInfoDto()
                {
                    Id          = userInfo.Id,
                    UserName    = userInfo.UserName,
                    Money       = userInfo.Money,
                    ClientIndex = currentClientIndex,
                    RoomId      = tmpRoom.Id
                });
                LogMessage.Instance.SetLogMessage(userInfo.Id.ToString());
            }
            #endregion

            #region 构造网络消息对象 广播给房间内的每一个客户端对象
            //构造服务端发送给客户端的网络消息对象
            this.message.ChangeMessage(OperationCode.Room, (int)RoomCode.JoinRoom_Response, roomInfoDto);
            //通过房间数据缓存对象根据指定房间编号进行房间内的消息广播,将网络消息发送给每一个房间内的客户端用户对象
            this.roomCache.BroadcastMessageByRoomId(tmpRoom.Id, this.message);
            #endregion

            #region 给房主广播一条空数据(没有实际作用,只是为了房主的数据同步工作,不会影响其他客户端对象)
            RoomInfo          tmpRoomInfo = this.roomCache.RoomIdRooms[tmpRoom.Id];      //获取房间信息对象
            List <ClientPeer> clients     = this.roomCache.RoomClientsDict[tmpRoomInfo]; //通过房间信息对象获取该房间内的客户端用户列表
            if (clients != null)                                                         //如果不为空的情况下
            {
                //默认给房主发送一个null数据(之前不这样做,会导致房主的数据不进行同步处理,出现了Bug,之后这样做,竟然神奇地解决了)
                this.message.ChangeMessage(OperationCode.Service, (int)ServiceCode.Passe_Response, "null");
                clients[0].OnSendMessage(this.message);
            }
            #endregion
        }
        /// <summary>
        /// 处理客户端对象创建房间的请求
        /// </summary>
        /// <param name="clientPeer">创建房间的客户端对象</param>
        /// <param name="createRoomData">客户端创建房间时传递过来的创建房间数据</param>
        private void ProcessCreateRoomRequest(ClientPeer clientPeer, object createRoomData = null)
        {
            RoomInfo newRoom = this.roomCache.CreateRoom(clientPeer);                                   //通过房间数据缓存对象创建并返回一个新的房间信息对象

            newRoom.PersonNumber++;                                                                     //累加房间人数
            int currentClientIndex = this.roomCache.GetRoomClientIndexByRoomId(clientPeer, newRoom.Id); //记录当前玩家所在的房间座位号

            #region 构建一个新的用户对象[后期从存储用户的用户数据服务器中取出对应的玩家数据]
            UserInfo userInfo = new UserInfo()
            {
                UserName         = clientPeer.ClientSocket.RemoteEndPoint.ToString(),
                RoomId           = newRoom.Id,
                Money            = 5000,
                ClientUserSocket = clientPeer.ClientSocket,
                ClientIndex      = currentClientIndex
            };
            this.userCache.AddUser(clientPeer, userInfo);               //将构建好的用户对象保存起来
            userInfo.Id = this.userCache.GetUserIdByUserInfo(userInfo); //设置用户编号
            #endregion

            #region 将用户添加到房间内
            //将用户对象添加到新房间的客户端用户列表中去
            newRoom.UserInfos.Add(userInfo);
            #endregion

            #region 构建要传输的数据房间对象并把客户端需要的数据发送过去
            //构建房间信息传输数据对象(用于服务端把房间数据传输给客户端)
            RoomInfoDto roomInfoDto = new RoomInfoDto()
            {
                Id           = newRoom.Id,
                EnterCode    = newRoom.EnterCode,
                Name         = newRoom.Name,
                PersonNumber = newRoom.PersonNumber,
                ServiceType  = (RoomInfoDto.RoomGameServiceType)Enum.Parse(typeof(GameServiceTypeCode), createRoomData.ToString())
            };

            #region 循环取出当前房间内的用户数据
            //循环遍历房间内的客户端用户对象列表
            for (int userIndex = 0; userIndex < newRoom.UserInfos.Count; userIndex++)
            {
                UserInfo tmpUserInfo = newRoom.UserInfos[userIndex];//取得当前循环遍历到的客户端用户对象数据
                //构建一个用户信息传输数据添加至房间信息数据传输对象的用户列表中
                roomInfoDto.Users.Add
                (
                    new UserInfoDto()
                {
                    Id          = tmpUserInfo.Id,
                    UserName    = tmpUserInfo.UserName,
                    Money       = tmpUserInfo.Money,
                    ClientIndex = currentClientIndex,
                    RoomId      = newRoom.Id
                }
                );
            }

            #region 通知客户端所在房间的座位号
            //通知客户端 你所在的房间中的座位号是
            this.message.ChangeMessage(OperationCode.Message, (int)MessageCode.SingleMessage, currentClientIndex.ToString());
            clientPeer.OnSendMessage(this.message);
            #endregion

            #endregion

            #endregion

            #region 构建网络消息并发送给创建房间的客户端对象
            //构造服务端发送给客户端的网络消息对象
            this.message.ChangeMessage(OperationCode.Room, (int)RoomCode.CreateRoom_Response, roomInfoDto);
            clientPeer.OnSendMessage(this.message);//由于只有一个创建房间的客户端对象,所以直接给这一个客户端对象发送网络消息即可
            #endregion

            LogMessage.Instance.SetLogMessage(
                string.Format("客户端对象唯一编号为 [ {0} ] 的用户创建了一个房间编号为 [ {1} ] 的新房间,这个房间的进入码为 [ {2} ]~", userInfo.Id.ToString(), newRoom.Id.ToString(), newRoom.EnterCode.ToString()));
            newRoom.RoomState = RoomState.Waiting;//将房间状态更改至等待中

            #region 创建房间后的 [洗牌] 和 [发牌] 阶段
            this.ProcessInitCreateRoomCardData(clientPeer, createRoomData, newRoom);//处理创建房间后需要做的一些初始化卡牌数据
            #endregion
        }