Exemplo n.º 1
0
        public bool CanJoinRoom(RoomViewModel model, string userId)
        {
            var room = this.Rooms.All().FirstOrDefault(x => x.Context.ToString() == model.Context);
            var canJoinRoom = false;

            if (room != null)
            {
                // If the current user is the room creator
                if (room.CreatorId == userId)
                {
                    canJoinRoom = true;
                }
                // If room is empty
                else if (room.MemberId == null || room.MemberId.Length < 1)
                {
                    canJoinRoom = true;
                    room.MemberId = userId;
                    this.Rooms.Update(room);
                    this.Rooms.SaveChanges();
                }
                // If current user is the room member 
                else if (room.MemberId != null && room.MemberId == userId)
                {
                    canJoinRoom = true;
                }
            }

            return canJoinRoom;
        }
Exemplo n.º 2
0
        public string Create(RoomViewModel model, string userId)
        {
            var roomContext = Guid.NewGuid();
            var roomCreator = this.Users.GetById(userId);

            var room = new Room
            {
                Context = roomContext,
                Name = model.Name,
                CreatorId = roomCreator.Id
            };

            roomCreator.Rooms.Add(room);
            this.Users.Update(roomCreator);
            this.Users.SaveChanges();

            if (room.Id == 0)
            {
                return ServicesConstants.RoomCreationFailed;
            }

            return room.Name;
        }