Esempio n. 1
0
        public ActionResult Create(Message message)
        {
            message.Timestamp = DateTime.Now;

            if (ModelState.IsValid)
            {
                // See if a conversion already exists
                var conversation = db.Conversations.GetConversation(message.UserId);

                if (conversation == null)
                {
                    // Create new
                    var newConversation = new Conversation
                    {
                        UserIdFrom = WebSecurity.CurrentUserId,
                        UserIdTo = message.UserId,
                        Timestamp = DateTime.Now,
                        Messages = new List<Message> {message}
                    };
                    message.ConversationId = newConversation.ConversationId;
                    db.Conversations.Add(newConversation);
                }
                else
                {
                    message.UserId = WebSecurity.CurrentUserId;
                    conversation.Messages.Add(message);
                    conversation.Timestamp = DateTime.Now;
                }

                // Set this user as online
                Helpers.User.SetOnline();

                db.Messages.Add(message);
                db.SaveChanges();
            }
            return RedirectToAction("Read", routeValues: new {id = message.ConversationId});
        }
Esempio n. 2
0
 public ActionResult Edit(Conversation conversation)
 {
     if (ModelState.IsValid)
     {
         db.Conversations.Update(conversation);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(conversation);
 }