Ejemplo n.º 1
0
        public IActionResult Chat(string GUID)
        {
            ViewBag.GUID = GUID;
            string name = repos1.GetOnGUID(GUID).Name;

            ViewBag.ChatName = name;

            if (User.Identity.IsAuthenticated)
            {
                User user1 = repos.GetUserOnEmail(this.User.FindFirstValue(ClaimTypes.Name));
                if (user1 == null)
                {
                    user1 = repos.GetUserOnEmail(this.User.FindFirstValue(ClaimTypes.Name));
                }
                List <Chat> mychats = repos.GetChats(user1.UserId);
                bool        Join    = true;
                foreach (Chat mychat in mychats)
                {
                    if (mychat.Name == name)
                    {
                        Join = false;
                    }
                }
                ViewBag.Join   = Join;
                ViewBag.Login  = user1.UserName;
                ViewBag.UserId = user1.UserId;
            }
            else
            {
                ViewBag.Join = false;
            }
            Chat myChat = repos1.GetChatOnName(name);

            ViewBag.Name = name;
            ViewBag.Id   = myChat.Id;
            List <Message> messages = repos1.GetMessages(myChat.Id);
            List <Message> texts    = new List <Message>();
            List <string>  logins   = new List <string>();
            int            kolvo    = Count;

            TempData.Keep("Count");
            int i             = 0;
            int messagesBegin = messages.Count() - kolvo - 10;
            int k             = 0;

            foreach (Message mes in messages)
            {
                if (mes.UserId != 0 && k > messagesBegin)
                {
                    if (mes.DocId != 0)
                    {
                        mes.Doc = repos3.GetDoc(mes.DocId);
                    }
                    texts.Add(mes);
                    User user = repos.Get(mes.UserId);
                    logins.Add(user.UserName);
                }
                k++;
            }
            bool load = messages.Count() > kolvo + 10;

            ViewBag.Load = load;
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Auth = true;
            }
            else
            {
                ViewBag.Auth = false;
            }
            ViewBag.Messages = messages;
            ViewBag.Texts    = texts;
            ViewBag.Names    = logins;
            return(View());
        }