Skip to content

Commit

Permalink
Update messages
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Dec 8, 2011
1 parent c0af704 commit 1fe2853
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
62 changes: 49 additions & 13 deletions JoMAR/Controllers/JasonController.cs
Expand Up @@ -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);
}

}
Expand Down
4 changes: 2 additions & 2 deletions JoMAR/Controllers/RoomsController.cs
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 10 additions & 7 deletions JoMAR/Views/Chat/Index.cshtml
Expand Up @@ -24,7 +24,6 @@
}
</ul>
</div>
<button type="button">Click Me!</button>
<div class="display-label">MessageBoard</div>
<div class="display-field">

Expand All @@ -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>
Expand Down

0 comments on commit 1fe2853

Please sign in to comment.