public void Send(string name, string message, string recipientName)
        {
            ChatRoomMessageService messageService = new ChatRoomMessageService();
            UsersService userService = new UsersService();
            ChatRoomsService roomService = new ChatRoomsService();

            if (recipientName != null)
            {
                ChatRoomMessage chatRoomMessage = new ChatRoomMessage();
                User sender = userService.FindUserByUsername(name);
                User recipient = userService.FindUserByUsername(recipientName);
                if (sender != null && recipient != null)
                {
                    chatRoomMessage.CreatedBy = sender.UserId;
                    chatRoomMessage.DateCreated = DateTime.Now;
                    chatRoomMessage.Message = message;
                    chatRoomMessage.SentTo = recipient.UserId;
                    int roomId = roomService.FindRoomIdForPrivateChat(chatRoomMessage);
                    if (roomId != -1)
                    {
                        chatRoomMessage.RoomId = roomId;
                    }
                    else
                    {
                        ChatRoom chatRoom = new ChatRoom();
                        chatRoom.CreatedBy = sender.UserId;
                        chatRoom.DateCreated = DateTime.Now;
                        chatRoom.IsDeleted = false;
                        chatRoom.RoomDescription = "Private chat";
                        chatRoom.RoomName = "Private_Chat";
                        chatRoom.IsPrivate = true;
                        int currentRoomId = roomService.CreateWithId(chatRoom);
                        chatRoomMessage.RoomId = currentRoomId;
                    }
                    messageService.Create(chatRoomMessage);
                    previousMessages = messageService.FindAllMessagesForCurrentRoom(chatRoomMessage.RoomId);
                    Clients.User(recipientName).addNewMessageToPage(name, message, recipientName, previousMessages);
                }
            }
            else
            {
                ChatRoomMessage chatRoomMessage = new ChatRoomMessage();
                User sender = userService.FindUserByUsername(name);
                if (sender != null)
                {
                    chatRoomMessage.CreatedBy = sender.UserId;
                    chatRoomMessage.DateCreated = DateTime.Now;
                    chatRoomMessage.Message = message;
                    chatRoomMessage.SentTo = null;
                    chatRoomMessage.RoomId = 1; // MASTER ROOM

                    messageService.Create(chatRoomMessage);
                    previousMessages = messageService.FindAllMessagesForCurrentRoom(chatRoomMessage.RoomId);
                    Clients.All.addNewMessageToPage(name, message, recipientName, previousMessages);
                }
            }
        }
        public void InitialCheckUp()
        {
            ChatRoomMessageService messageService = new ChatRoomMessageService();
            ChatRoomsService roomService = new ChatRoomsService();
            List<ChatMessageModel> previousMessages = new List<ChatMessageModel>();
            ChatRoomMessage chatRoomMessage = new ChatRoomMessage();

            previousMessages = messageService.FindAllMessagesForCurrentRoom(1);
            Clients.All.addNewMessageToPageInitial(previousMessages);
        }
        public IList<ChatMessageModel> LoadPrivateMessagesHistory(string userFrom, string userTo)
        {
            UsersService userService = new UsersService();
            ChatRoomMessageService msgService = new ChatRoomMessageService();
            User sender = userService.FindUserByUsername(userFrom);
            User recipient = userService.FindUserByUsername(userTo);

            ChatRoomMessage messageTemp = new ChatRoomMessage();
            messageTemp.CreatedBy = sender.UserId;
            messageTemp.SentTo = recipient.UserId;

            int roomId = FindRoomIdForPrivateChat(messageTemp);

            if (roomId != -1)
            {
                return msgService.FindAllMessagesForCurrentRoom(roomId).ToList();
            }

            return null;
        }