Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update messages

  • Loading branch information...
commit 1fe2853ca41460705e4280ad25c74c51456ce75a 1 parent c0af704
unknown authored
View
62 JoMAR/Controllers/JasonController.cs
@@ -18,24 +18,60 @@ public ActionResult Index()
public JsonResult getMessages(Guid id)
{
- List<dynamic> list = new List<dynamic>();
+
JodADataContext db = new JodADataContext();
+ List<string> messages = new List<string>();
+ int i = 0;
+
+ ChatRoom room = (from p in db.ChatRooms
+ where p.RoomID == id
+ select p).First();
+
+ ChatMessage[] msg = room.ChatMessages.ToArray();
+
+ foreach (var message in msg)
+ {
+ messages.Add(message.Date + " " + message.aspnet_User.UserName + " said: " + message.Text);
+ i++;
+ }
+ messages.Sort();
+ return Json(messages.ToArray(), JsonRequestBehavior.AllowGet);
- dynamic msg = (from p in db.ChatMessages
- where p.RoomID == id
- select p.Text).ToList();
+ }
+
+ /* public JsonResult addMessage(Guid id)
+ {
+ JodADataContext db = new JodADataContext();
+ ChatMessage message = new ChatMessage();
+ message.Date = DateTime.Now;
+ message.MessageID = Guid.NewGuid();
+ message.UserID = (from p in db.aspnet_Users
+ where p.UserName == User.Identity.Name
+ select p).First().UserId;
+ message.RoomID = id;
+ //message.Text = collection["Message"];
+
+
+ // Submit message to DB
+ db.ChatMessages.InsertOnSubmit(message);
+ db.SubmitChanges();
+ }*/
+
+ public JsonResult getRooms()
+ {
+ JodADataContext db = new JodADataContext();
+ List<string> rooms = new List<string>();
- //foreach (string o in msg)
- //{
- // var myOp = new
- // {
- // text = o.Text
+ ChatRoom[] room = (from p in db.ChatRooms
+ where p.isPublic
+ select p).ToArray();
- // };
- // list.Add(myOp);
- //}
- return Json(msg, JsonRequestBehavior.AllowGet);
+ foreach (var r in room)
+ {
+ rooms.Add("Name: " + r.Name + " Owner: " + r.aspnet_User.UserName);
+ }
+ return Json(rooms.ToArray(), JsonRequestBehavior.AllowGet);
}
}
View
4 JoMAR/Controllers/RoomsController.cs
@@ -39,7 +39,7 @@ public ActionResult edit(Guid id)
JodADataContext db = new JodADataContext();
ChatRoom room = (from p in db.ChatRooms
- where p.RoomID.ToString() == Url.RequestContext.RouteData.Values.Last().Value
+ where p.RoomID.ToString() == (String)Url.RequestContext.RouteData.Values.Last().Value
select p).First();
return View(room);
@@ -127,7 +127,7 @@ public ActionResult delete(Guid id)
JodADataContext db = new JodADataContext();
ChatRoom room = (from p in db.ChatRooms
- where p.RoomID.ToString() == Url.RequestContext.RouteData.Values.Last().Value
+ where p.RoomID.ToString() == (String)Url.RequestContext.RouteData.Values.Last().Value
select p).First();
return View(room);
View
17 JoMAR/Views/Chat/Index.cshtml
@@ -24,7 +24,6 @@
}
</ul>
</div>
- <button type="button">Click Me!</button>
<div class="display-label">MessageBoard</div>
<div class="display-field">
@@ -33,15 +32,19 @@
<script type="text/javascript">
Messages.scrollTop = Messages.scrollHeight;
- window.setInterval(yourfunction, 500);
+ window.setInterval(getPosts, 100);
- function yourfunction() {
- $.getJSON("/Jason/getMessages/@Model.RoomID", function (result) {
-
- $("textarea#Messages").val(result.join("\n"));
-
+ function getPosts() {
+ $.getJSON("/Jason/getMessages/@Model.RoomID", function (result) {
+ $("textarea#Messages").val(result.join("\n"));
});
}
+
+ function publishMessage {
+ $("#target").submit(function(e){
+ alert("Submitted");
+ });
+ }
</script>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.