Exemple #1
0
 public List<User> AllUsers()
 {
     List<User> Users = new List<User>();
     using (var cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename" +
      "=|DataDirectory|\\Database.mdf; Integrated Security=True"))
     {
         string _sql = @"SELECT [Username], [LastActivity] FROM [dbo].[System_Users]";
         var cmd = new SqlCommand(_sql, cn);
         cn.Open();
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             while(reader.Read())
             {
                 User item = new User();
                 item.UserName = reader["Username"].ToString();
                 item.LastActivity = Convert.ToDateTime(reader["LastActivity"].ToString());
                 Users.Add(item);
             }
             reader.Dispose();
             cmd.Dispose();
         }
     }
     return Users;
 }
        public ActionResult getOrganizedMessages()
        {
            MessagesModel message = new MessagesModel();
            var messages = message.RecieveMessages(User.Identity.Name);
            List<string> Recipients = new List<string>();
            List<List<MessagesModel>> organizedMessages = new List<List<MessagesModel>>();
            for (int i = 0; i < messages.Count(); i++)
            {
                if (messages[i].From != User.Identity.Name && !Recipients.Contains(messages[i].From))
                {
                    Recipients.Add(messages[i].From);
                }
                if (messages[i].To != User.Identity.Name && !Recipients.Contains(messages[i].To))
                {
                    Recipients.Add(messages[i].To);
                }
            }
            foreach (var recipient in Recipients)
            {
                List<MessagesModel> item = new List<MessagesModel>();
                for (int i = 0; i < messages.Count(); i++)
                {
                    if (messages[i].From.Contains(recipient) || messages[i].To.Contains(recipient))
                    {
                        item.Add(messages[i]);
                    }
                }
                organizedMessages.Add(item);
            }
            User userlist = new User();
            var listUsers = userlist.AllUsers();
            List<SelectListItem> obj = new List<SelectListItem>();
            int count = 0;
            foreach (var item in listUsers)
            {
                if (User.Identity.Name != item.UserName)
                {
                    obj.Add(new SelectListItem { Text = item.UserName, Value = count.ToString() });
                    count++;
                }
            }
            ViewBag.data = obj;
            MessagePageModel m = new MessagePageModel();
            m.organizedMessages = organizedMessages;

            return PartialView(m);
        }
 public ActionResult Messages()
 {
     if (User.Identity.IsAuthenticated)
     {
         User userlist = new User();
         var listUsers = userlist.AllUsers();
         List<SelectListItem> obj = new List<SelectListItem>();
         int count = 0;
         foreach (var item in listUsers)
         {
             if (User.Identity.Name != item.UserName)
             {
                 obj.Add(new SelectListItem { Text = item.UserName, Value = count.ToString() });
                 count++;
             }
         }
         ViewBag.data = obj;
         return View();
     }
     return RedirectToAction("Login", "Account");
 }