public ActionResult Create(conversation conv)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            return(View());
        }
        public ActionResult Create(conversation conv)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:2663/");

                client.PostAsJsonAsync <conversation>("api/conversation", conv).ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        public ActionResult Chat(string email)
        {
            var              newUser       = User as CustomPrincipal;
            ChatModel        cm            = new ChatModel();
            List <ChatModel> conversations = new List <ChatModel>();

            using (DisDBContext db = new DisDBContext())
            {
                ViewBag.Email = newUser.UserEmail;
                var authUser = db.Users.FirstOrDefault(p => p.id == newUser.UserId);
                ViewBag.FullName = authUser.last_name.Trim() + " " + authUser.first_name.Trim();
                var user = db.Users.FirstOrDefault(p => p.email == email);
                ViewBag.ConvName = user.last_name + " " + user.first_name;
                conversation con = db.Conversations.FirstOrDefault(p => p.user1 == newUser.UserEmail && p.user2 == email || p.user2 == newUser.UserEmail && p.user1 == email);
                if (con != null)
                {
                    ViewBag.ConvId = con.id;
                    foreach (var msg in db.Messages.Where(p => p.conversation_id == con.id))
                    {
                        conversations.Add(new ChatModel
                        {
                            fname    = user.first_name,
                            lname    = user.last_name,
                            date     = msg.date.ToString("dd.MM.yyyy hh:mm"),
                            msg      = msg.msg,
                            sender   = (msg.sender == newUser.UserEmail) ? 1 : 0,
                            msg_type = msg.msg_type
                        });
                    }
                }
                else
                {
                    //Add new conversation

                    var conver = db.Conversations.Add(new conversation
                    {
                        user1 = newUser.UserEmail,
                        user2 = email
                    });
                    db.SaveChanges();
                    ViewBag.ConvId = conver.id;
                }
                // ViewBag.Conversation = conversations;
            }

            return(View(conversations));
        }
Example #4
0
        public BaseModel()  //Конструктор – для экземпляра класса
        {
            // Users region
            User        = new user();
            Users       = new List <user>();
            Company     = new company();
            Companies   = new List <company>();
            Departments = new List <department>();

            // Document region
            Documents        = new List <document>();
            DocumentsHistory = new List <document>();
            DocumentsInbox   = new List <document>();

            //ChatModel region
            conversation = new conversation();
            message      = new message();
            ChatModel    = new ChatModel();
        }
Example #5
0
 private async void getConversations(String user)
 {
     logged = true;
     this.user = user;
     HttpWebRequest req = WebRequest.CreateHttp("http://jmex.altervista.org/getConversations.php");
     req.Method = "POST";
     req.ContentType = "application/x-www-form-urlencoded";
     req.Credentials = CredentialCache.DefaultCredentials;
     req.Headers["X-Requested-With"] = "XMLHttpRequest";
     String usr = "******" + user;
     Byte[] usrData = Encoding.UTF8.GetBytes(usr);
     Stream s = await req.GetRequestStreamAsync();
     s.Write(usrData, 0, usrData.Length);
     s.Flush();
     HttpWebResponse resp = (HttpWebResponse)await req.GetResponseAsync();
     String response = new StreamReader(resp.GetResponseStream()).ReadToEnd();
     JsonArray array = JsonArray.Parse(response);
     //convText.Text += Environment.NewLine + response;
     int count = array.Count;
     convList.Clear();
     conversation general = new conversation();
     general.fileName = "demo_post.json";
     general.name = "general";
     convList.Add(general);
     for (uint i = 0; i < count; i++)
     {
         if (array.GetObjectAt(i).ValueType == JsonValueType.Object)
         {
             JsonObject obj = array.GetObjectAt(i);
             //convText.Text = Environment.NewLine + obj["filename"] + " / " + obj["name"];
             conversation conv = new conversation();
             conv.name = obj["name"].GetString();
             conv.fileName = obj["filename"].GetString();
             convList.Add(conv);
         }
     }
     updateList();
 }
Example #6
0
        public void SendChatMessage(string sender, string email, string message, string clientName)
        {
            foreach (var connectionId in _connections.GetConnections(email))
            {
                Clients.Client(connectionId).addChatMessage(sender, email, message, clientName);
            }
            ClientService                   CS  = new ClientService();
            client                          cls = CS.Get(x => x.email.Equals(sender));
            client                          clr = CS.Get(x => x.email.Equals(email));
            ConversationUsersService        CUS = new ConversationUsersService();
            IEnumerable <conversation_user> conversationsuserslist = CUS.GetMany();
            ConversationService             COS = new ConversationService();
            IEnumerable <conversation>      conversationslist = COS.GetMany();
            conversation                    c0 = null;
            int s = 0;

            foreach (conversation c in conversationslist)
            {
                s = 0;
                foreach (conversation_user cu in conversationsuserslist)
                {
                    if (cu.Conversation_idConversation == c.idConversation && (cu.participants_idUser == cls.idUser || cu.participants_idUser == clr.idUser))
                    {
                        s++;
                    }
                }
                if (s > 1)
                {
                    c0 = c;
                    break;
                }
            }
            if (c0 == null)
            {
                c0 = new conversation
                {
                    startDate = DateTime.Now
                };
                conversation_user cu1 = new conversation_user
                {
                    conversation = c0,
                    Conversation_idConversation = c0.idConversation,
                    participants_idUser         = cls.idUser
                };
                conversation_user cu2 = new conversation_user
                {
                    conversation = c0,
                    Conversation_idConversation = c0.idConversation,
                    participants_idUser         = clr.idUser
                };
                c0.conversation_user.Add(cu1);
                c0.conversation_user.Add(cu2);
                COS.Add(c0);
                COS.Commit();
            }
            MessageService MS = new MessageService();
            message        m  = new message
            {
                content = message,
                conversation_idConversation = c0.idConversation,
                sendingDate   = DateTime.Now,
                sender_idUser = cls.idUser
            };
            message_user mu = new message_user
            {
                Message_idMessage = m.idMessage,
                receivers_idUser  = clr.idUser
            };

            m.message_user.Add(mu);
            MS.Add(m);
            MS.Commit();
        }
 public void callMeBack(conversation c)
 {
     this.callbackC = c;
 }