Skip to content

Commit

Permalink
Answertype added to question
Browse files Browse the repository at this point in the history
  • Loading branch information
mule committed Oct 22, 2011
1 parent 374f013 commit 199c933
Show file tree
Hide file tree
Showing 43 changed files with 134,641 additions and 79 deletions.
9 changes: 6 additions & 3 deletions DotNetQuiz/Areas/Admin/Controllers/AdminHomeController.cs
Expand Up @@ -19,6 +19,7 @@ public class AdminHomeController : Controller
public ActionResult Index()
{
var vm = new QuestionsListViewModel();
vm.LoadData();
return View(vm);
}

Expand Down Expand Up @@ -46,7 +47,7 @@ public ActionResult Details(int id)

public ActionResult Create()
{
return View();
return View( new QuestionEditViewModel());
}

//
Expand Down Expand Up @@ -74,7 +75,7 @@ public ActionResult CreateQuestion(QuestionEditViewModel vm)
List<string> messages = new List<string>();
var val = validateQuestion(vm);


vm.Id = null;
try
{

Expand All @@ -84,6 +85,7 @@ public ActionResult CreateQuestion(QuestionEditViewModel vm)


QuestionManager.Insert(question);
UnitOfWork.Commit();

messages.Add("Question created succesfully.");
}
Expand Down Expand Up @@ -180,7 +182,8 @@ public ActionResult Delete(int id, FormCollection collection)

private Question CreateQuestionFromViewModel(QuestionEditViewModel vm)
{
Question q = new Question() {QuestionText = vm.QuestionText, QuestionId = vm.QuestionId};

Question q = new Question() {QuestionText = vm.QuestionText, Id = vm.Id, QuestionAnswerType = vm.AnswerType};

int id = 1;
q.AnswerOptions = new List<Tuple<int, string, bool>>();
Expand Down
2 changes: 2 additions & 0 deletions DotNetQuiz/Areas/Admin/ViewModels/AnswerOptionViewModel.cs
Expand Up @@ -2,12 +2,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DotNetQuiz.Areas.Admin.ViewModels
{
public class AnswerOptionViewModel
{
public int AnswerId { get; set; }
[AllowHtml]
public string AnswerText { get; set; }
public bool Correct { get; set; }
}
Expand Down
27 changes: 26 additions & 1 deletion DotNetQuiz/Areas/Admin/ViewModels/QuestionEditViewModel.cs
Expand Up @@ -2,14 +2,39 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNetQuizDataAccess.Models;

namespace DotNetQuiz.Areas.Admin.ViewModels
{
public class QuestionEditViewModel
{
public int QuestionId { get; set; }
public readonly SelectList AnswerTypes;




public string Id { get; set; }
[AllowHtml]
public string QuestionText { get; set; }
[AllowHtml]
public List<AnswerOptionViewModel> AnswerOptions { get; set; }

public Question.AnswerType AnswerType { get; set; }


public QuestionEditViewModel()
{
var values =
Enum.GetValues(typeof (Question.AnswerType)).Cast<Question.AnswerType>().Select(
e => new KeyValuePair<int, string>((int)e,e.ToString()));


AnswerTypes = new SelectList(values,"Key","Value");
}




}
}
2 changes: 1 addition & 1 deletion DotNetQuiz/Areas/Admin/ViewModels/QuestionViewModel.cs
Expand Up @@ -7,7 +7,7 @@ namespace DotNetQuiz.Areas.Admin.ViewModels
{
public class QuestionViewModel
{
public int QuestionId { get; set; }
public string Id { get; set; }
public string QuestionText { get; set; }
public List<Tuple<int,string>> AnswerOptions { get; set; }
}
Expand Down
54 changes: 24 additions & 30 deletions DotNetQuiz/Areas/Admin/Views/AdminHome/Create.cshtml
Expand Up @@ -4,58 +4,52 @@

}

@using DotNetQuiz.Areas.Admin.ViewModels
@model QuestionEditViewModel

@section AdditionalScripts
{
<script type="text/javascript" src="@Url.Content("~/Scripts/DotNetQuiz.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script>
}

@using (Html.BeginForm("Create", "AdminHome")){

<div id="QuestionText">
<textarea id="txtQuestion">
@using (Html.BeginForm("Create", "AdminHome"))
{
<div id="QuestionInput">
<div id="QuestionText">
<textarea id="txtQuestion">

</textarea>
</div>
<button id='btnAddAnswer'>Add anwswer</button>
<div id="AnswerOptions">

</textarea>
</div>

@Html.DropDownList("AnswerType",@Model.AnswerTypes,"Answertype:")
<button id='btnAddAnswer'>
Add anwswer</button>
<div id="AnswerOptions">
</div>
</div>

<div id="CRUDControls">
<button id='btnCreateQuestion'>Create Question</button>
<button id='btnCreateQuestion'>
Create Question</button>
</div>


}


}
@section scripts{

<script id="answerOptionEditTemplate" type="text/x-jquery-tmpl">
<script id="answerOptionEditTemplate" type="text/x-jquery-tmpl">
<div class="answerOption">
<textarea class="txtAnswerOption">
</textarea>
<input type='checkbox' class='cbxCorrect'>Correct answer</input>
<button class='removeAnswerBtn'>Remove</button>
</div>
</script>

<script type="text/javascript" >
var qEditor = new QuestionEditor();
</script>
<script type="text/javascript">
var qEditor = new QuestionEditor();
</script>
</script>
}

@section footer
{

}




9 changes: 6 additions & 3 deletions DotNetQuiz/Areas/Admin/Views/AdminHome/Index.cshtml
Expand Up @@ -17,16 +17,19 @@
@{
Html.Telerik().Grid(Model.Questions)
.Name("QuestionsGrid")
.DataKeys(dataKeys => dataKeys.Add(c => c.Id))
.Columns(columns =>
{
columns.Bound(o => o.QuestionId).Width(20);
columns.Bound(o => o.QuestionText).Width(200);
columns.Bound(o => o.Id).Width(20);
columns.Bound(o => o.QuestionText);
columns.Command(commands => commands.Select()).Title("Edit");
})
.DataBinding(dataBinding =>
{

dataBinding.Ajax().Select("AjaxBinding", "Grid");
dataBinding.Ajax().Select("AjaxBinding", "AdminHome");
})
.Selectable()
.Render();
}

Expand Down
58 changes: 26 additions & 32 deletions DotNetQuiz/Areas/Admin/Views/Shared/_AdminLayout.cshtml
Expand Up @@ -2,30 +2,30 @@
@{
ViewBag.Title = "DotNetQuiz Admin";
}


<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<meta name = "viewport" content = "width = device-width" />
<title>DotNet Quiz</title>

<!--[if IE]>
<meta charset="utf-8" />
<meta name="viewport" content="width = device-width" />
<title>DotNet Quiz</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
<!--[if lte IE 7]>
<script src="js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->
<link href="@Url.Content("~/Content/AdminMain.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/AdminMain.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/2011.2.712/telerik.common.min.css")" rel="stylesheet" type="text/css"/>
<link href="@Url.Content("~/Content/2011.2.712/telerik.sunset.min.css")" rel="stylesheet" type="text/css"/>
<link href="@Url.Content("~/Content/2011.2.712/telerik.rtl.min.css")" rel="stylesheet" type="text/css"/>


<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Scripts/2011.2.712/telerik.common.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/2011.2.712/telerik.grid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/2011.2.712/telerik.common.min.js")" type="text/javascript"></script>
@RenderSection("AdditionalScripts")

@*
@{
Html.Telerik().StyleSheetRegistrar()
Expand All @@ -36,23 +36,17 @@
.Add("telerik.rtl.css")
.Combined(true)
.Compress(true));
}

}*@
</head>
<h2>DotNetQuiz Admin</h2>

<div id="mainContent" >

@RenderBody()


</div>



<footer>
@RenderSection("footer")
</footer>
@RenderSection("scripts")
<body>
<h2>
DotNetQuiz Admin</h2>
<div id="MainContent">
@RenderBody()
</div>
<footer>
@RenderSection("footer")
</footer>
@RenderSection("scripts")
</body>
</html>
</html>
12 changes: 12 additions & 0 deletions DotNetQuiz/Content/AdminMain.css
@@ -0,0 +1,12 @@
#MainContent {
width: 100%; }

#QuestionInput {
margin: 20px; }

#QuestionInput TextArea {
width: 300px;
height: 300px; }

#AnswerOptions TextArea {
height: 150px; }
22 changes: 21 additions & 1 deletion DotNetQuiz/Content/AdminMain.scss
@@ -1,2 +1,22 @@
body {

#MainContent{
width:100%;

}

#QuestionInput{
margin: 20px;

}
#QuestionInput TextArea {
width:300px;
height: 300px;

}

#AnswerOptions TextArea{

height: 150px;


}
2 changes: 1 addition & 1 deletion DotNetQuiz/Controllers/QuizController.cs
Expand Up @@ -60,7 +60,7 @@ public ActionResult NextQuestion()

var question = new QuestionViewModel()
{
QuestionId = 1,
Id = "1",
QuestionText = questionStr,
AnswerOptions =
new List<Tuple<int, string>> { answer1,answer2,asnwer3,answer4}
Expand Down
6 changes: 6 additions & 0 deletions DotNetQuiz/DotNetQuiz.csproj
Expand Up @@ -97,6 +97,12 @@
<Reference Include="WebActivator">
<HintPath>..\packages\WebActivator.1.4.4\lib\net40\WebActivator.dll</HintPath>
</Reference>
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.8.0.1549\lib\xunit.dll</HintPath>
</Reference>
<Reference Include="xunit.extensions">
<HintPath>..\packages\xunit.extensions.1.8.0.1549\lib\xunit.extensions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="App_GlobalResources\EditorLocalization.bg-BG.designer.cs">
Expand Down
7 changes: 6 additions & 1 deletion DotNetQuiz/Scripts/DotNetQuiz.js
Expand Up @@ -2,11 +2,13 @@ function QuestionEditor() {

var questionText = '';
var answerOptions = new Array();


var me = this;

this.QuestionText = questionText;
this.AnswerOptions = answerOptions;
this.AnswerType = 0;



Expand All @@ -16,6 +18,7 @@ function QuestionEditor() {
var questionTxtBox = $('#txtQuestion');
var answerOptionsBox = $('#AnswerOptions');
var answerOptionTemplate = $('#answerOptionEditTemplate');
var answerTypeDropDown = $('#AnswerType');

wireEvents();

Expand All @@ -25,6 +28,8 @@ function QuestionEditor() {
QuestionEditor.prototype.CreateQuestion = function () {
getQuestionText();
getAnswerOptions();
me.AnswerType = $(answerTypeDropDown).val();

sendQuestionToServer();
};

Expand Down Expand Up @@ -77,7 +82,7 @@ function QuestionEditor() {
$.ajax({
url: "/Admin/AdminHome/CreateQuestion",
type: "POST",
data: $.toDictionary({ QuestionText: me.QuestionText, AnswerOptions: me.AnswerOptions}),
data: $.toDictionary({ QuestionText: me.QuestionText, AnswerOptions: me.AnswerOptions, AnswerType: me.AnswerType}),
datatype: "json",
success: function (result) {
alert(result);
Expand Down

0 comments on commit 199c933

Please sign in to comment.