Ejemplo n.º 1
0
        public static int AcceptRequest(LoginUser loginUser, int userID, int chatRequestID, string ipAddress)
        {
            ChatRequest request = ChatRequests.GetChatRequest(loginUser, chatRequestID);

            if (request == null || request.IsAccepted)
            {
                return(-1);
            }
            request.IsAccepted   = true;
            request.TargetUserID = userID;
            request.Collection.Save();

            Chats.JoinChat(loginUser, userID, ChatParticipantType.User, request.ChatID, ipAddress);

            if (request.RequestType == ChatRequestType.External && request.Message.Trim() != "")
            {
                ChatMessage chatMessage = (new ChatMessages(loginUser)).AddNewChatMessage();
                chatMessage.ChatID     = request.ChatID;
                chatMessage.Message    = request.Message.Trim();
                chatMessage.PosterID   = request.RequestorID;
                chatMessage.PosterType = request.RequestorType;
                chatMessage.Collection.Save();
            }

            return(request.ChatID);
        }
Ejemplo n.º 2
0
        public static ChatRequest RequestChat(LoginUser loginUser, int organizationID, string firstName, string lastName, string email, string message, string ipAddress, int groupID = 0)
        {
            ChatClients clients = new ChatClients(loginUser);
            ChatClient  client  = clients.IsEmpty ? (new ChatClients(loginUser)).AddNewChatClient() : clients[0];

            client.OrganizationID = organizationID;
            client.FirstName      = firstName;
            client.LastName       = lastName;
            client.Email          = email;
            Users users = new Users(loginUser);

            if (!string.IsNullOrEmpty(email))
            {
                users.LoadByEmail(organizationID, email);

                try
                {
                    if (!users.IsEmpty)
                    {
                        client.LinkedUserID = users[0].UserID;
                        client.CompanyName  = Organizations.GetOrganization(loginUser, users[0].OrganizationID).Name;
                    }
                    else
                    {
                        string       emailDomain = email.Substring(email.LastIndexOf('@') + 1).Trim();
                        Organization org         = Organization.GetCompanyByDomain(organizationID, emailDomain, loginUser);
                        client.CompanyName = (org != null) ? org.Name : "";
                    }
                }
                catch (Exception)
                {
                    client.CompanyName = "";
                }
            }
            else
            {
                Organization org = Organization.GetCompanyByDomain(organizationID, string.Empty, loginUser, forceUnknown: true);
                client.CompanyName = (org != null) ? org.Name : "";
            }

            client.Collection.Save();


            Chat chat = (new Chats(loginUser)).AddNewChat();

            chat.InitiatorID    = client.ChatClientID;
            chat.InitiatorType  = ChatParticipantType.External;
            chat.OrganizationID = organizationID;
            chat.Collection.Save();

            Chats.JoinChat(loginUser, client.ChatClientID, ChatParticipantType.External, chat.ChatID, ipAddress);

            ChatRequest request = (new ChatRequests(loginUser)).AddNewChatRequest();

            request.RequestorID    = client.ChatClientID;
            request.RequestorType  = ChatParticipantType.External;
            request.OrganizationID = organizationID;
            request.ChatID         = chat.ChatID;
            request.Message        = message;
            request.IsAccepted     = false;
            request.RequestType    = ChatRequestType.External;
            request.GroupID        = groupID;
            request.Collection.Save();

            return(request);
        }