public ActionResult SelectFriend(User model)
        {
            var currentUser = context.Users.Find(WebSecurity.CurrentUserId);
            var friend = context.Users.Find(model.Id);
            var sentMessages = currentUser.SentMessages
                .Where(m => m.Receiver.Id == friend.Id);
            var receivedMessages = currentUser.ReceivedMessages
                .Where(m => m.Sender.Id == friend.Id);
            var messages = sentMessages.Union(receivedMessages)
                .OrderBy(m => m.DateTime);

            return PartialView("MessagesPartial", messages);
        }
        public ActionResult SendMessage(User friend, string text)
        {
            var currentUser = context.Users.Find(WebSecurity.CurrentUserId);
            var user = context.Users.Find(friend.Id);

            var message = new Message
            {
                Sender = currentUser,
                Receiver = user,
                Text = text,
                DateTime = DateTime.Now
            };

            context.Messages.Add(message);
            context.SaveChanges();

            return PartialView("MessagePartial", message);
        }
        public ActionResult SendRequest(User model)
        {
            var currentUser = context.Users.Find(WebSecurity.CurrentUserId);
            var user = context.Users.Find(model.Id);

            var request = new Request
            {
                Sender = currentUser,
                Receiver = user,
                DateTime = DateTime.Now,
                StatusDateTime = DateTime.Now
            };

            context.Requests.Add(request);
            context.SaveChanges();

            var users = Users();

            return PartialView("UsersPartial", users);
        }
Esempio n. 4
0
 public NewsController()
 {
     context = new MyContext();
     currentUser = context.Users.Find(WebSecurity.CurrentUserId);
 }