Commit 4e2908eea9a882c5f44d596efb4226be61e0c4c0
1 parent
75263b72
added back-end code fro lab execrice save
Showing
6 changed files
with
347 additions
and
79 deletions
400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
... | ... | @@ -130,6 +130,7 @@ |
130 | 130 | <DependentUpon>Global.asax</DependentUpon> |
131 | 131 | </Compile> |
132 | 132 | <Compile Include="Models\DBModel.cs" /> |
133 | + <Compile Include="Models\LabExercise.cs" /> | |
133 | 134 | <Compile Include="Models\PixelLocator.cs" /> |
134 | 135 | <Compile Include="Models\User.cs" /> |
135 | 136 | <Compile Include="Models\UserUtility.cs" /> | ... | ... |
400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs
1 | -using Newtonsoft.Json.Linq; | |
1 | +using Newtonsoft.Json; | |
2 | +using Newtonsoft.Json.Linq; | |
2 | 3 | using System; |
3 | 4 | using System.Collections.Generic; |
4 | 5 | using System.Linq; |
5 | 6 | using System.Net; |
6 | 7 | using System.Net.Http; |
7 | 8 | using System.Web.Http; |
9 | +using log4net; | |
10 | +using AIAHTML5.API.Constants; | |
11 | +using AIAHTML5.API.Models; | |
12 | +using System.Collections; | |
8 | 13 | |
14 | +using System.Data.SqlClient; | |
9 | 15 | namespace AIAHTML5.API.Controllers |
10 | 16 | { |
11 | 17 | public class LabExerciseController : ApiController |
12 | 18 | { |
13 | - // GET api/<controller> | |
19 | + // GET api/authenticate | |
14 | 20 | public IEnumerable<string> Get() |
15 | 21 | { |
16 | 22 | return new string[] { "value1", "value2" }; |
17 | 23 | } |
18 | 24 | |
19 | - // GET api/<controller>/5 | |
25 | + // GET api/authenticate/5 | |
20 | 26 | public string Get(int id) |
21 | 27 | { |
22 | 28 | return "value"; |
23 | 29 | } |
24 | 30 | |
25 | - // POST api/<controller> | |
26 | - public void Post([FromBody]JObject labExerciseUserAttemptData) | |
31 | + // POST api/authenticate | |
32 | + public HttpResponseMessage Post([FromBody]JArray labExerciseUserAttemptData) | |
27 | 33 | { |
34 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
35 | + logger.Debug("inside insertLabExerciseAttempt Post LabExerciseController"); | |
36 | + | |
37 | + try | |
38 | + { | |
39 | + LabExercise le = new LabExercise(); | |
40 | + le.labExercise = new List<LabEcerciseDetails>(); | |
41 | + | |
42 | + foreach (var item in labExerciseUserAttemptData.Children()) | |
43 | + { | |
44 | + var itemProperties = item.Children<JProperty>(); | |
45 | + //you could do a foreach or a linq here depending on what you need to do exactly with the value | |
46 | + var userId = itemProperties.FirstOrDefault(x => x.Name == "userId"); | |
47 | + le.userId = Convert.ToInt32(userId.Value); ////This is a JValue type | |
48 | + | |
49 | + var labExerciseIdentifier = itemProperties.FirstOrDefault(x => x.Name == "labExerciseIdentifier"); | |
50 | + le.labExerciseIdentifier = labExerciseIdentifier.Value.ToString(); ////This is a JValue type | |
51 | + | |
52 | + var lastQuestion = itemProperties.FirstOrDefault(x => x.Name == "LastQuestion"); | |
53 | + le.lastQuestion = Convert.ToInt32(lastQuestion.Value); ////This is a JValue type | |
54 | + | |
55 | + var totalQuestions = itemProperties.FirstOrDefault(x => x.Name == "TotalQuestions"); | |
56 | + le.totalQuestions = Convert.ToInt32(totalQuestions.Value); ////This is a JValue type | |
57 | + | |
58 | + var LabExerciseUserData = itemProperties.FirstOrDefault(x => x.Name == "LabExerciseUserData"); | |
59 | + foreach (var labQuiz in LabExerciseUserData.Children()) | |
60 | + { | |
61 | + var labQuizProperties = labQuiz.Children(); | |
62 | + foreach (var lb in labQuizProperties) | |
63 | + { | |
64 | + var itemProperties1 = lb.Children<JProperty>(); | |
65 | + | |
66 | + LabEcerciseDetails labExDetails = new LabEcerciseDetails(); | |
67 | + | |
68 | + var MaxScore = itemProperties1.FirstOrDefault(x => x.Name == "MaxScore"); | |
69 | + labExDetails.MaxScore = Convert.ToInt32(MaxScore.Value); | |
70 | + | |
71 | + var UserAnswer = itemProperties1.FirstOrDefault(x => x.Name == "UserAnswer"); | |
72 | + labExDetails.UserAnswer = UserAnswer.Value.ToString(); | |
73 | + | |
74 | + var QuestionNo = itemProperties1.FirstOrDefault(x => x.Name == "QuestionNo"); | |
75 | + labExDetails.QuestionNo = Convert.ToInt32(QuestionNo.Value); | |
76 | + | |
77 | + var CorrectAnswer = itemProperties1.FirstOrDefault(x => x.Name == "CorrectAnswer"); | |
78 | + labExDetails.CorrectAnswer = CorrectAnswer.Value.ToString(); | |
79 | + | |
80 | + var DragItems = itemProperties1.FirstOrDefault(x => x.Name == "DragItems"); | |
81 | + labExDetails.DragItems = DragItems.Value.ToString(); | |
82 | + | |
83 | + var Score = itemProperties1.FirstOrDefault(x => x.Name == "Score"); | |
84 | + labExDetails.Score = Convert.ToInt32(Score.Value); | |
85 | + | |
86 | + | |
87 | + | |
88 | + le.labExercise.Add(labExDetails); | |
89 | + | |
90 | + } | |
91 | + } | |
92 | + } | |
93 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("insertyed") }; | |
94 | + | |
95 | + } | |
96 | + catch (SqlException e) | |
97 | + { | |
98 | + | |
99 | + //logger.Fatal("SqlException occured for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); | |
100 | + | |
101 | + //ArrayList supportMailList = UserUtility.GetSupportMailList(); | |
102 | + //string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT; | |
103 | + //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; | |
104 | + //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody); | |
105 | + | |
106 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; | |
107 | + } | |
108 | + catch (Exception e) | |
109 | + { | |
110 | + | |
111 | + //logger.Fatal("Exception occured for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); | |
112 | + | |
113 | + //ArrayList supportMailList = UserUtility.GetSupportMailList(); | |
114 | + //string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT; | |
115 | + //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; | |
116 | + //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody); | |
117 | + | |
118 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.EXCEPTION_OCCURED) }; | |
119 | + | |
120 | + } | |
121 | + | |
122 | + | |
123 | + | |
28 | 124 | } |
29 | 125 | |
30 | - // PUT api/<controller>/5 | |
126 | + | |
127 | + | |
128 | + | |
129 | + | |
130 | + | |
131 | + | |
132 | + // PUT api/authenticate/5 | |
31 | 133 | public void Put(int id, [FromBody]string value) |
32 | 134 | { |
33 | 135 | } |
34 | 136 | |
35 | - // DELETE api/<controller>/5 | |
137 | + // DELETE api/authenticate/5 | |
36 | 138 | public void Delete(int id) |
37 | 139 | { |
38 | 140 | } | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... | ... | @@ -861,5 +861,18 @@ namespace AIAHTML5.API.Models |
861 | 861 | |
862 | 862 | return result; |
863 | 863 | } |
864 | + | |
865 | + internal int InsertLabExerciseData(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, List<> labExDetails ) | |
866 | + { | |
867 | + return 1; | |
868 | + | |
869 | + } | |
870 | + | |
871 | + | |
872 | + internal int InsertLabExerciseDetails(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, List<> labExDetails ) | |
873 | + { | |
874 | + return 1; | |
875 | + | |
876 | + } | |
864 | 877 | } |
865 | 878 | } |
866 | 879 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs
0 → 100644
1 | +using log4net; | |
2 | +using System; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
5 | +using System.Web; | |
6 | + | |
7 | +namespace AIAHTML5.API.Models | |
8 | +{ | |
9 | + public class LabExercise | |
10 | + { | |
11 | + | |
12 | + public int userId { get; set; } | |
13 | + public string labExerciseIdentifier { get; set; } | |
14 | + public int lastQuestion { get; set; } | |
15 | + public int totalQuestions { get; set; } | |
16 | + public List<LabEcerciseDetails> labExercise; | |
17 | + | |
18 | + | |
19 | + internal static int insertLabExerciseAttempt(int userId, string labExerciseIdentifier, int LastQuestion, int TotalQuestions, List<LabEcerciseDetails> labExercise) | |
20 | + { | |
21 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
22 | + logger.Debug("inside insertLabExerciseAttempt for UserId =" + userId + ",labExerciseIdentifier= " + labExerciseIdentifier + ",LastQuestion= " + LastQuestion+ "TotalQuestions =" + TotalQuestions); | |
23 | + | |
24 | + | |
25 | + int result = 0; | |
26 | + | |
27 | + DBModel objModel = new DBModel(); | |
28 | + | |
29 | + result = objModel.InsertLoginDetails(userId); | |
30 | + | |
31 | + return result; | |
32 | + } | |
33 | + | |
34 | + } | |
35 | + | |
36 | + public class LabEcerciseDetails | |
37 | + { | |
38 | + | |
39 | + public int MaxScore { get; set; } | |
40 | + public string UserAnswer { get; set; } | |
41 | + public int QuestionNo { get; set; } | |
42 | + public string CorrectAnswer { get; set; } | |
43 | + public string DragItems { get; set; } | |
44 | + public int Score { get; set; } | |
45 | + } | |
46 | +} | |
0 | 47 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js
... | ... | @@ -10,10 +10,12 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
10 | 10 | $scope.Title = ""; |
11 | 11 | $scope.Imagepath = ""; |
12 | 12 | $scope.DraggedList = []; |
13 | - $scope.AnswerList = []; | |
13 | + $scope.UserAttempt = []; | |
14 | 14 | $scope.UserAnswersForAllQuestions = []; |
15 | + $scope.LabExerciseUserData = []; | |
15 | 16 | $scope.LabExercise = []; |
16 | 17 | $scope.dragableId = ""; |
18 | + $scope.UserAttempt = []; | |
17 | 19 | $scope.blReviewAttempt = false; |
18 | 20 | $scope.$on('$viewContentLoaded', function (event) { |
19 | 21 | // code that will be executed ... |
... | ... | @@ -84,6 +86,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
84 | 86 | if (title != null) { |
85 | 87 | $scope.LabExerciseQuiz = title; |
86 | 88 | $scope.LabExerciseName = title.Topic; |
89 | + $scope.LabExerciseUserData = []; | |
87 | 90 | $location.url("/lab-exercises-detail?labexercise=" + (title.Slug || "")); |
88 | 91 | } |
89 | 92 | |
... | ... | @@ -95,6 +98,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
95 | 98 | $scope.LabExerciseName = keywords.labexercise; |
96 | 99 | $scope.LabExerciseModules = null; |
97 | 100 | $scope.LabExerciseBoxes = null; |
101 | + | |
98 | 102 | //alert($scope.LabExerciseName) |
99 | 103 | var labExerciseModulePath = '~/../content/data/json/le/' + $scope.LabExerciseName + '.json'; |
100 | 104 | |
... | ... | @@ -109,6 +113,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
109 | 113 | $scope.TotalNumberofQuiz = result.LabExercise[index].NumberofQuestions; |
110 | 114 | $.each(result.LabExercise[index].Questions, function (index1, value1) { |
111 | 115 | if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) { |
116 | + $scope.MaxScore = result.LabExercise[index].Questions[index1].Options.length; | |
112 | 117 | if (result.LabExercise[index].Questions[index1].ImagePath == "") { |
113 | 118 | $("#imgblock").css("display", "none"); |
114 | 119 | //$("#imgblock").remove(); |
... | ... | @@ -150,14 +155,16 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
150 | 155 | |
151 | 156 | $scope.nextQuiz = function () { |
152 | 157 | //need to save all questions till the current question number when user clicks on save |
153 | - if ($scope.dragableId!="") { | |
154 | - $scope.UserAnswersForAllQuestions.push({'QuestionNo':$scope.quiznumber,'UserAnswer':$scope.AnswerList}) | |
158 | + //if ($scope.dragableId!="") { | |
159 | + // $scope.UserAnswersForAllQuestions.push({'QuestionNo':$scope.quiznumber,'UserAnswer':$scope.UserAttempt}) | |
160 | + | |
161 | + //} | |
162 | + //else { | |
163 | + // //need to anattampted question means user ahs not dragged, dropped options so save blank | |
164 | + // $scope.UserAnswersForAllQuestions.push({ 'QuestionNo': $scope.quiznumber, 'UserAnswer': "" }) | |
165 | + //} | |
166 | + $scope.CreateLabExerciseDataToSave(); | |
155 | 167 | |
156 | - } | |
157 | - else { | |
158 | - //need to anattampted question means user ahs not dragged, dropped options so save blank | |
159 | - $scope.UserAnswersForAllQuestions.push({ 'QuestionNo': $scope.quiznumber, 'UserAnswer': "" }) | |
160 | - } | |
161 | 168 | $scope.dragableId = ""; |
162 | 169 | if ($scope.quiznumber == $scope.TotalNumberofQuiz) |
163 | 170 | return; |
... | ... | @@ -168,7 +175,11 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
168 | 175 | } |
169 | 176 | |
170 | 177 | $scope.prevQuiz = function () { |
178 | + | |
179 | + $scope.CreateLabExerciseDataToSave(); | |
180 | + | |
171 | 181 | $scope.dragableId = ""; |
182 | + $scope.UserAttempt = []; | |
172 | 183 | if ($scope.quiznumber == 1) |
173 | 184 | return; |
174 | 185 | else |
... | ... | @@ -184,6 +195,21 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
184 | 195 | e.dataTransfer.setData('text/plain', this.innerHTML); |
185 | 196 | $scope.dragableId = $(this).attr("Id"); |
186 | 197 | |
198 | + //if user drag already selected answer from one blankbox to another than it gets id of blank box so need to get answer | |
199 | + if ($scope.dragableId.indexOf('T') != -1) { | |
200 | + var optionText = document.getElementById($scope.dragableId).innerHTML; | |
201 | + var currentQuizData = new jinqJs() | |
202 | + .from($scope.LabExData.LabExercise[0].Questions) | |
203 | + .where('Number == ' + $scope.quiznumber) | |
204 | + .select(); | |
205 | + var optionData = new jinqJs() | |
206 | + .from(currentQuizData[0].Options) | |
207 | + .where('OptionTitle == ' + optionText) | |
208 | + .select(); | |
209 | + var option = optionData[0].OptionNumber; | |
210 | + $scope.dragableId = optionText + '-' + option; | |
211 | + } | |
212 | + | |
187 | 213 | }; |
188 | 214 | |
189 | 215 | $scope.handleDragEnd = function (e) { |
... | ... | @@ -214,15 +240,15 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
214 | 240 | $.each(result.LabExercise[index].Questions, function (index1, value1) { |
215 | 241 | if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) { |
216 | 242 | var Options = result.LabExercise[index].Questions[index1].Options; |
217 | - $scope.maxScore = Options.length; | |
243 | + | |
218 | 244 | |
219 | 245 | $.each(Options, function (inx, value2) { |
220 | 246 | if (Options[inx].OptionTitle == item) { |
221 | 247 | if ($scope.DraggedList != null) { |
222 | 248 | $.each($scope.DraggedList, function (inx1, value3) { |
223 | - // $scope.AnswerList.push({ "optionName": id.split('-')[1], "AnswerName": $scope.dragableId.split('-')[1] }); | |
224 | - var balnkBox=id.split('-')[1]; | |
225 | - $scope.UserAttempt.push({balnkBox :+ $scope.dragableId.split('-')[1] }); | |
249 | + $scope.UserAttempt.push({ "BlankBoxName": id.split('-')[1], "OptionName": $scope.dragableId.split('-')[1] }); | |
250 | + //var balnkBox=id.split('-')[1]; | |
251 | + //$scope.UserAttempt.push({balnkBox :+ $scope.dragableId.split('-')[1] }); | |
226 | 252 | if ($scope.DraggedList[inx1].Value == item) { |
227 | 253 | $scope.DraggedList.splice(inx1, 1); |
228 | 254 | $('#block-' + Options[inx].OptionNumber).css("display", "block"); |
... | ... | @@ -264,8 +290,9 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
264 | 290 | } |
265 | 291 | }); |
266 | 292 | } |
267 | - | |
268 | - $scope.AnswerList.push({ "optionName": id.split('-')[1], "AnswerName": $scope.dragableId.split('-')[1] }); | |
293 | + //var balnkBox = id.split('-')[1]; | |
294 | + //$scope.UserAttempt.push({ balnkBox: +$scope.dragableId.split('-')[1] }); | |
295 | + $scope.UserAttempt.push({ "BlankBoxName": id.split('-')[1], "OptionName": $scope.dragableId.split('-')[1] }); | |
269 | 296 | $scope.DraggedList.push({ "id": id.split('-')[1], "optionName": id.split('-')[1], "Value": dataText, "topcoord": Options[inx].topcoord, "leftcoord": Options[inx].leftcoord }); |
270 | 297 | //$('#' + $scope.dragableId).remove(); |
271 | 298 | $('#' + $scope.dragableId).css("display", "none"); |
... | ... | @@ -291,7 +318,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
291 | 318 | //{ |
292 | 319 | // $("#divoptions").html("<br><br><br><br>") |
293 | 320 | //} |
294 | - //alert(JSON.stringify($scope.AnswerList)); | |
321 | + //alert(JSON.stringify($scope.UserAttempt)); | |
295 | 322 | }; |
296 | 323 | |
297 | 324 | $scope.handleDragOver = function (e) { |
... | ... | @@ -302,6 +329,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
302 | 329 | |
303 | 330 | $scope.resetQuiz = function () { |
304 | 331 | $scope.DraggedList = []; |
332 | + $scope.UserAttempt = []; | |
305 | 333 | $scope.GetQuizByTopic(); |
306 | 334 | }; |
307 | 335 | |
... | ... | @@ -362,8 +390,84 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
362 | 390 | }; |
363 | 391 | |
364 | 392 | $scope.SaveAnswer = function () { |
393 | + $scope.CreateLabExerciseDataToSave(); | |
394 | + | |
395 | + | |
396 | + //LabExerciseService.saveLabExerciseAttempt("superadmin", $scope.LabExerciseAttemptedData) | |
397 | + $scope.labExerciseAttempt = []; | |
398 | + $scope.labExerciseAttempt.push({ 'LabExerciseUserData': $scope.LabExerciseUserData, 'userId': $scope.userId, 'labExerciseIdentifier': $scope.labExerciseIdentifier, 'LastQuestion': $scope.LastQuestion, 'TotalQuestions': $scope.TotalQuestions }); | |
399 | + LabExerciseService.saveLabExerciseAttempt($scope.labExerciseAttempt) | |
400 | + .then( | |
401 | + function (result) { | |
402 | + alert("Successfully updated"); | |
403 | + }, | |
404 | + function (error) { | |
405 | + console.log(' Error in authentication = ' + error.statusText); | |
406 | + alert("Error"); | |
407 | + }); | |
408 | + }; | |
365 | 409 | |
410 | + | |
411 | + $scope.CreateLabExerciseDataToSave = function () { | |
412 | + | |
413 | + $scope.LabExerciseAttemptedData = []; | |
414 | + $scope.lb = []; | |
366 | 415 | //get user answers |
416 | + $scope.getUserAnswers(); | |
417 | + | |
418 | + | |
419 | + //get correct response | |
420 | + $scope.getCorrectResponse(); | |
421 | + | |
422 | + // $scope.correctResponseForSavingDatabaseArray = $scope.correctResponseForSavingDatabase.split(','); | |
423 | + | |
424 | + //get dragItems | |
425 | + $scope.getDragItems(); | |
426 | + | |
427 | + //get score | |
428 | + $scope.getScore(); | |
429 | + | |
430 | + $scope.userId = JSON.parse(localStorage.getItem('loggedInUserDetails')).Id; | |
431 | + $scope.labExerciseIdentifier = $scope.labExercideIdentifier; | |
432 | + $scope.LastQuestion = $scope.quiznumber; | |
433 | + $scope.TotalQuestions = $scope.TotalNumberofQuiz; | |
434 | + | |
435 | + $scope.LabExerciseAttemptedData = { | |
436 | + | |
437 | + MaxScore: $scope.MaxScore, | |
438 | + UserAnswer: $scope.commaSeperatedUserAnswers, | |
439 | + QuestionNo: $scope.quiznumber, | |
440 | + CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase), | |
441 | + DragItems: $scope.DragItems, | |
442 | + Score: $scope.Score | |
443 | + } | |
444 | + | |
445 | + var thisQuestiondataInLabExerciseUserData = new jinqJs() | |
446 | + .from($scope.LabExerciseUserData) | |
447 | + .where('QuestionNo == ' + $scope.LabExerciseAttemptedData.QuestionNo) | |
448 | + .select(); | |
449 | + if (thisQuestiondataInLabExerciseUserData.length>0) { | |
450 | + | |
451 | + angular.forEach($scope.LabExerciseUserData, function (value, key) { | |
452 | + if (value.QuestionNo == $scope.LabExerciseAttemptedData.QuestionNo) { | |
453 | + | |
454 | + } | |
455 | + else { | |
456 | + $scope.lb.push(value); | |
457 | + } | |
458 | + }) | |
459 | + $scope.LabExerciseUserData = []; | |
460 | + | |
461 | + $scope.lb.push($scope.LabExerciseAttemptedData); | |
462 | + angular.forEach($scope.lb,function(value1,key1){ | |
463 | + $scope.LabExerciseUserData.push(value1); | |
464 | + }) | |
465 | + } | |
466 | + else | |
467 | + $scope.LabExerciseUserData.push($scope.LabExerciseAttemptedData); | |
468 | + } | |
469 | + | |
470 | + $scope.getUserAnswers = function () { | |
367 | 471 | var userAnswers = []; |
368 | 472 | var blockBoxes = $("div[id*='blockbox']"); |
369 | 473 | var blockBoxesInTextBlock = $("#textblock").children(); |
... | ... | @@ -373,80 +477,78 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
373 | 477 | for (var i = 0; i < blockAnswers.length; i++) { |
374 | 478 | |
375 | 479 | var id = (blockAnswers[i].id).split('-')[1]; |
376 | - userAnswers[id.replace('T','')] = blockAnswers[i].innerHTML; | |
480 | + userAnswers[id.replace('T', '')] = blockAnswers[i].innerHTML; | |
377 | 481 | } |
378 | 482 | |
379 | - var commaSeperatedUserAnswers = ''; | |
380 | - for (var i = 1; i <=blockBoxLength; i++) { | |
381 | - | |
382 | - var userAns = userAnswers[i]; | |
383 | - if(userAns!=undefined){ | |
384 | - commaSeperatedUserAnswers +=userAns + ','; | |
385 | - } | |
386 | - else{ | |
387 | - commaSeperatedUserAnswers +=''+','; | |
388 | - } | |
483 | + $scope.commaSeperatedUserAnswers = ''; | |
484 | + for (var i = 1; i <= blockBoxLength; i++) { | |
485 | + | |
486 | + var userAns = userAnswers[i]; | |
487 | + if (userAns != undefined) { | |
488 | + $scope.commaSeperatedUserAnswers += userAns + ','; | |
489 | + } | |
490 | + else { | |
491 | + $scope.commaSeperatedUserAnswers += '' + ','; | |
492 | + } | |
389 | 493 | } |
390 | 494 | //remove last comma |
391 | - commaSeperatedUserAnswers = commaSeperatedUserAnswers.replace(/,$/, ''); | |
392 | - | |
495 | + $scope.commaSeperatedUserAnswers = $scope.commaSeperatedUserAnswers.replace(/,$/, ''); | |
496 | + } | |
393 | 497 | |
394 | - //get correct response | |
395 | - $scope.correctResponse =''; | |
396 | - $scope.correctResponseForSavingDatabase =''; | |
397 | - var cr = new jinqJs() | |
498 | + $scope.getCorrectResponse = function () { | |
499 | + $scope.correctResponse = ''; | |
500 | + $scope.correctResponseForSavingDatabase = ''; | |
501 | + var cr = new jinqJs() | |
398 | 502 | .from($scope.LabExData.LabExercise[0].Questions) |
399 | 503 | .where('Number == ' + $scope.quiznumber) |
400 | 504 | .select(); |
401 | 505 | for (var i = 0; i < cr[0].correctResponse.length; i++) { |
402 | 506 | var blankBox = cr[0].correctResponse[i].OptionBox; |
403 | - var options = cr[0].correctResponse[i].Answer; | |
404 | - $scope.correctResponse += blankBox + ' ' + options + ','; | |
405 | - $scope.correctResponseForSavingDatabase += parseInt(blankBox.replace('T',''))-1 + ':' + options + ','; | |
507 | + var option = cr[0].correctResponse[i].Answer; | |
508 | + | |
509 | + var options = new jinqJs() | |
510 | + .from(cr[0].Options) | |
511 | + .where('OptionNumber == ' + option) | |
512 | + .select(); | |
513 | + var optionText = options[0].OptionTitle; | |
514 | + $scope.correctResponse += blankBox + ' ' + option + ','; | |
515 | + $scope.correctResponseForSavingDatabase += parseInt(blankBox.replace('T', '')) - 1 + ':' + optionText + ','; | |
406 | 516 | } |
407 | 517 | |
408 | 518 | $scope.correctResponse = $scope.correctResponse.replace(/,$/, ''); |
409 | 519 | $scope.correctResonseKeyValue = $scope.correctResponse.split(','); |
410 | 520 | |
411 | 521 | $scope.correctResponseForSavingDatabase = $scope.correctResponseForSavingDatabase.replace(/,$/, ''); |
412 | - // $scope.correctResponseForSavingDatabaseArray = $scope.correctResponseForSavingDatabase.split(','); | |
522 | + } | |
413 | 523 | |
414 | - //get dragItems | |
524 | + | |
525 | + $scope.getDragItems = function () { | |
415 | 526 | var OptionBoxes = $("div[id*='block-']"); |
416 | 527 | $scope.DragItems = ''; |
417 | 528 | for (var i = 0; i < OptionBoxes.length; i++) { |
418 | 529 | $scope.DragItems += OptionBoxes[i].id.replace('block-', '') + ',' + OptionBoxes[i].innerHTML + ';'; |
419 | 530 | } |
420 | - $scope.DragItems = DragItems.replace(/;$/, ''); | |
531 | + $scope.DragItems = $scope.DragItems.replace(/;$/, ''); | |
421 | 532 | |
533 | + } | |
422 | 534 | |
423 | - //get score | |
535 | + $scope.getScore = function () { | |
424 | 536 | |
425 | - $scope.LabExerciseAttemptedData = { | |
426 | - userId: localStorage.getItem('loggedInUserDetails').id, | |
427 | - //Attemptnumber: 1, | |
428 | - labExerciseIdentifier: $scope.labExercideIdentifier, | |
429 | - LastQuestion: $scope.quiznumber, | |
430 | - TotalQuestions: $scope.TotalNumberofQuiz, | |
431 | - MaxScore: $scope.maxScore, | |
432 | - UserAnswer: commaSeperatedUserAnswers, | |
433 | - QuestionNo: $scope.quiznumber, | |
434 | - CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase), | |
435 | - DragItems: $scope.DragItems, | |
436 | - Score: 1 | |
437 | - } | |
438 | - var abc = $scope.AnswerList; | |
439 | - //LabExerciseService.saveLabExerciseAttempt("superadmin", $scope.LabExerciseAttemptedData) | |
440 | - LabExerciseService.saveLabExerciseAttempt($scope.LabExerciseAttemptedData) | |
441 | - .then( | |
442 | - function (result) { | |
443 | - alert("Successfully updated"); | |
444 | - }, | |
445 | - function (error) { | |
446 | - console.log(' Error in authentication = ' + error.statusText); | |
447 | - alert("Error"); | |
448 | - }); | |
449 | - }; | |
537 | + var abc = $scope.UserAttempt; | |
538 | + $scope.Score = 0; | |
539 | + angular.forEach($scope.UserAttempt, function (value, key) { | |
540 | + | |
541 | + var userOptedAnswer = value.BlankBoxName + ' ' + value.OptionName; | |
542 | + for(var i=0;i<$scope.correctResonseKeyValue.length;i++) { | |
543 | + if (userOptedAnswer == $scope.correctResonseKeyValue[i]) { | |
544 | + $scope.Score += 1; | |
545 | + } | |
546 | + | |
547 | + } | |
548 | + | |
549 | + | |
550 | + }) | |
551 | + } | |
450 | 552 | }] |
451 | 553 | |
452 | 554 | ); | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js
1 | -AIA.factory('LabExerciseService', function ($http, $q) { | |
1 | +AIA.factory('LabExerciseService', function ($http, $q,$rootScope) { | |
2 | 2 | return { |
3 | - saveLabExerciseAttempt: function (username, labExercieObj) { | |
3 | + saveLabExerciseAttempt: function (labExercieObj) { | |
4 | 4 | var deferred = $q.defer(); |
5 | - | |
6 | - $http.post('/API/api/Authenticate', JSON.stringify(userInfo), { | |
7 | - headers: { | |
8 | - 'Content-Type': 'application/json' | |
9 | - } | |
10 | - }) | |
5 | + $http.post('/API/api/LabExercise', JSON.stringify(labExercieObj), { | |
6 | + headers: { | |
7 | + 'Content-Type': 'application/json' | |
8 | + } | |
9 | + }) | |
10 | + //$http.post('/API/api/LabExercise', JSON.stringify(labExercieObj, userId, labExerciseIdentifier, LastQuestion, TotalQuestions), { | |
11 | + // headers: { | |
12 | + // 'Content-Type': 'application/json' | |
13 | + // } | |
14 | + //}) | |
11 | 15 | .success(function (data, status, headers, config) { |
12 | 16 | console.log('success') |
13 | 17 | deferred.resolve(data); | ... | ... |