Skip to content

Commit

Permalink
FIxur
Browse files Browse the repository at this point in the history
  • Loading branch information
Overhead committed Dec 9, 2011
1 parent 9524ac0 commit 97cad2b
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 30 deletions.
25 changes: 16 additions & 9 deletions JoMAR/Controllers/JasonController.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Diagnostics;

namespace JoMAR.Controllers
{
Expand Down Expand Up @@ -41,19 +42,25 @@ public JsonResult getMessages(Guid id)

public JsonResult getRooms()
{
//Fiks problem seinar


JodADataContext db = new JodADataContext();
List<string> rooms = new List<string>();
//List<ChatRoom> rooms = new List<ChatRoom>();

ChatRoom[] room = (from p in db.ChatRooms
where p.isPublic
select p).ToArray();
ChatRoom[] rooms = (from p in db.ChatRooms
where p.isPublic
select p).ToArray();

foreach (var r in room)
{
rooms.Add("Name: " + r.Name + " Owner: " + r.aspnet_User.UserName);
}
//foreach (var r in room)
// rooms.Add("Room: " + r.Name + " Owner: " + r.aspnet_User.UserName);
Debug.WriteLine(rooms[0].Name);
Debug.WriteLine(rooms[0].aspnet_User.UserName);
JsonResult m = Json(rooms.ToArray(), JsonRequestBehavior.AllowGet);

Debug.WriteLine(m.Data);

return Json(rooms.ToArray(), JsonRequestBehavior.AllowGet);
return m;
}

public JsonResult getUsersOnRoom(Guid id)
Expand Down
40 changes: 40 additions & 0 deletions JoMAR/Controllers/UploadController.cs
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;



namespace JoMAR.Controllers
{
public class UploadController : Controller
{
//
// GET: /Upload/

public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{

// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index");
}

}
}
6 changes: 6 additions & 0 deletions JoMAR/Global.asax.cs
Expand Up @@ -21,6 +21,12 @@ public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"UploadFile",
"Chat/UploadFile",
new { controller = "Chat", action = "UploadFile", id = UrlParameter.Optional }
);

routes.MapRoute(
"Profile",
"Chat/Profile",
Expand Down
2 changes: 2 additions & 0 deletions JoMAR/JoMAR.csproj
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Controllers\JasonController.cs" />
<Compile Include="Controllers\EssemessController.cs" />
<Compile Include="Controllers\RoomsController.cs" />
<Compile Include="Controllers\UploadController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
Expand Down Expand Up @@ -191,6 +192,7 @@
<Content Include="Views\Rooms\ViewPage1.cshtml" />
<Content Include="Views\Chat\Profile.cshtml" />
<Content Include="Views\Essemess\Index.cshtml" />
<Content Include="Views\Chat\UploadFile.cshtml" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
Expand Down
9 changes: 6 additions & 3 deletions JoMAR/Views/Chat/Index.cshtml
Expand Up @@ -4,15 +4,15 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@Html.DisplayTextFor(model => model.Name)</h2>
<h2>Chatroom: @Html.DisplayTextFor(model => model.Name)</h2>



@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>ChatModel</legend>
<legend>Chatting</legend>
<div class="display-label right-float"></div>
<div class="display-field right-float">
<h4>Users</h4>
Expand All @@ -32,10 +32,13 @@
@Html.EditorFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>

<p>
<input type="submit" value="Publish message" class="button" />
@Html.ActionLink("Upload File", "UploadFile")
</p>



</fieldset>
}
<script type="text/javascript">
Expand Down
49 changes: 49 additions & 0 deletions JoMAR/Views/Chat/UploadFile.cshtml
@@ -0,0 +1,49 @@
@model JoMAR.Models.ChatModel

@{
ViewBag.Title = "UploadFile";
Layout = "~/Views/Shared/_Layout.cshtml";
}


<h2>UploadFile</h2>


<h2>Chatroom: @Html.DisplayTextFor(model => model.Name)</h2>



@using (Html.BeginForm("Index", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Chatting</legend>
<div class="display-label right-float"></div>
<div class="display-field right-float">
<h4>Users</h4>
<ul>
<select id="lb" style="width:250px" multiple="multiple" size="10"> </select>
</ul>
</div>
<div class="display-label left-float"> MessageBoard</div>
<div class="display-field left-float">
@Html.TextArea("Messages",new { @class = "messageBoard"})
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Message)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>
<p>
<input type="file" name="file" />
<input type="submit" value="OK" />
</p>



</fieldset>
}

41 changes: 23 additions & 18 deletions JoMAR/Views/Rooms/Public.cshtml
Expand Up @@ -10,7 +10,7 @@
<p>
@Html.ActionLink("Create New chatroom", "create")
</p>
<table>
<table id="chatRooms">
<tr>
<th>
Chatrooms
Expand All @@ -21,21 +21,26 @@
<th></th>
</tr>

@foreach (var item in Model) {
if (item.isPublic)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.aspnet_User.UserName)
</td>
<td>
@Html.ActionLink("Enter" + (item.isPrivate ? " Private" : ""), "", "Chat/" + item.Name)
</td>
</tr>
}
}

</table>

<script type="text/javascript">
window.setInterval(getRooms, 5000);
$(document).ready(function () {
getRooms()
});
function getRooms() {
$.getJSON("/Jason/getRooms", function (data) {
var html = '<tr><th> ChatRooms </th><th> Owner of room </th><th></th></tr>';
var len = data.length;
for (var i = 0; i < len; i++) {
html += '<tr><td>' + data[i].Name + '</td><td>' + data[i].aspnet_User.UserName + '</td></tr>';
}
$('#chatRooms').html(html);
});
}
</script>
</table>

0 comments on commit 97cad2b

Please sign in to comment.