diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
index 2b9b559..d371aeb 100644
--- a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
@@ -43,6 +43,6 @@ namespace AIAHTML5.API.Constants
public const string UNBLOCK_USER_EMAIL_SUBJECT = "Unblock user request mail for:";
public const string LAB_EXERCISE_SAVE_SUCCESS = "Your lab exercise attempt is saved successfully.";
public const string LAB_EXERCISE_SAVE_FAILURE = "We are unable to save your lab exercise attempt, please try again.";
-
+ public const string SAVED_LAB_EXERCISE_NOT_FOUND = "Saved Lab Exercise not found.";
}
}
\ No newline at end of file
diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
index 5e75a0b..a2d5ffb 100644
--- a/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
@@ -28,5 +28,7 @@ namespace AIAHTML5.API.Constants
public const string GET_BLOCKED_USER_BY_USER_ID = "GetBlockedUserByUserId";
public const string GET_BLOCKED_USERS_BY_USER_TYPE = "GetBlockedUserByUserType";
public const string SAVE_LAB_EXERCISE_ATTEMPT = "usp_SaveLabExerciseAttempts";
+ public const string GET_LAB_EXERCISE = "GetLabExcerciseByUserId";
+
}
}
\ No newline at end of file
diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs
index 56ff042..9f619b9 100644
--- a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs
@@ -19,15 +19,54 @@ namespace AIAHTML5.API.Controllers
public class LabExerciseController : ApiController
{
// GET api/LabExercise
- public IEnumerable Get()
- {
- return new string[] { "value1", "value2" };
- }
+ //public IEnumerable Get()
+ //{
+ // return new string[] { "value1", "value2" };
+ //}
// GET api/LabExercise/5
- public string Get(int id)
+ public HttpResponseMessage Get([FromUri] int userId, string labExerciseIdentifier)
{
- return "value";
+ ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
+ logger.Debug("inside Get LabExerciseController");
+
+ try
+ {
+ DBModel db = new DBModel();
+ LabExercise labEx = db.GetLabExercise(userId, labExerciseIdentifier);
+
+ if (labEx!=null)
+ return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(labEx)) };
+ else
+ return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.SAVED_LAB_EXERCISE_NOT_FOUND) };
+
+ }
+
+ catch (SqlException ex)
+ {
+ logger.Fatal("SqlException occured for UserId =" + userId.ToString() + " and LabExerciseIdentifier= " + labExerciseIdentifier + "Exception= " + ex.Message + ", STACKTRACE: " + ex.StackTrace);
+
+ ArrayList supportMailList = UserUtility.GetSupportMailList();
+ string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT;
+ string mailBody = "MESSAGE: " + ex.Message + ", STACKTRACE: " + ex.StackTrace;
+ UserUtility.SendEmailForException(userId, supportMailList, "", mailSubject, mailBody);
+
+ return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) };
+
+ }
+ catch (Exception e)
+ {
+ logger.Fatal("SqlException occured for UserId =" + userId.ToString() + " and LabExerciseIdentifier= " + labExerciseIdentifier + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
+
+ ArrayList supportMailList = UserUtility.GetSupportMailList();
+ string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT;
+ string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
+ UserUtility.SendEmailForException(userId, supportMailList, "", mailSubject, mailBody);
+
+ return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) };
+
+ }
+
}
// POST api/LabExercise
@@ -96,6 +135,7 @@ namespace AIAHTML5.API.Controllers
DataTable labExerciseDetailsDataTable = new UserUtility().ToDataTable(le.labExercise);
int result = le.insertLabExerciseAttempt(le, labExerciseDetailsDataTable);
+
if (result == -1)
{
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LAB_EXERCISE_SAVE_SUCCESS) };
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
index 194d19a..e239563 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
@@ -862,10 +862,8 @@ namespace AIAHTML5.API.Models
return result;
}
- // internal int SaveLabExerciseAttempt(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, DataTable labExeciseQuizAttemptedData )
internal int SaveLabExerciseAttempt(LabExercise le, DataTable labExeciseQuizAttemptedData)
-
- {
+ {
logger.Debug(" inside InsertUserLoginLog for userId= " + le.userId + ", labExerciseIdentifier= " + le.labExerciseIdentifier + ",lastQusetion= " + le.lastQuestion + ",totalQuestions=" + le.totalQuestions);
@@ -900,7 +898,68 @@ namespace AIAHTML5.API.Models
}
-
+ internal LabExercise GetLabExercise(int userId, string labIdentifier)
+ {
+
+
+ logger.Debug(" Inside GetUserDetailsByEmailId for userId = " + userId + "and labIdentifier= " + labIdentifier);
+
+ LabExercise le = new LabExercise();
+ le.labExercise = new List();
+ DBModel objModel = new DBModel();
+
+ SqlConnection conn = new SqlConnection(dbConnectionString);
+ SqlCommand cmd = new SqlCommand();
+ SqlDataAdapter adapter;
+ SqlParameter param;
+ DataSet ds = new DataSet();
+
+ cmd.Connection = conn;
+ cmd.CommandText = DBConstants.GET_LAB_EXERCISE;
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ //cmd.Parameters.AddWithValue("@UserId", userId);
+ //cmd.Parameters.AddWithValue("@Identifier", labIdentifier);
+ cmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;
+ cmd.Parameters.Add("@Identifier", SqlDbType.NVarChar).Value = labIdentifier;
+
+
+ adapter = new SqlDataAdapter(cmd);
+ adapter.Fill(ds);
+
+
+ if (ds != null && ds.Tables.Count > 0)
+ {
+ DataTable dt = ds.Tables[0];
+
+ if (dt.Rows.Count > 0)
+ {
+ foreach (DataRow dr in dt.Rows)
+ {
+ le.userId = Convert.ToInt32(dr["UserId"]);
+ le.labExerciseIdentifier = dr["labExerciseIdentifier"].ToString();
+
+ le.lastQuestion = Convert.ToInt32(dr["LastQuestion"]);
+ le.totalQuestions = Convert.ToInt32(dr["TotalQuestions"]);
+
+ LabEcerciseDetails led = new LabEcerciseDetails();
+ led.StateObject = dr["StateObject"].ToString();
+ led.UserAnswers = dr["UserAnswers"].ToString();
+ led.Score = Convert.ToInt32(dr["Score"]);
+ led.MaxScore = Convert.ToInt32(dr["MaxScore"]);
+ led.QuestionNo = Convert.ToInt32(dr["QuestionNo"]);
+ led.CorrectAnswers = dr["CorrectAnswers"].ToString();
+ led.DragItems = dr["DragItems"].ToString();
+ le.labExercise.Add(led);
+ }
+ }
+ }
+
+ return le;
+
+
+
+ }
//internal int InsertLabExerciseDetails(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, List<> labExDetails )
//{
// return 1;
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs b/400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs
index 4f0b40f..29ac084 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs
@@ -32,6 +32,16 @@ namespace AIAHTML5.API.Models
return result;
}
+ internal LabExercise GetLabExercise(int userId, string labExIdentifier)
+ {
+ DBModel objModel = new DBModel();
+
+ LabExercise le = objModel.GetLabExercise(userId, labExIdentifier);
+
+ return le;
+
+ }
+
}
@@ -44,5 +54,6 @@ namespace AIAHTML5.API.Models
public string CorrectAnswers { get; set; }
public string DragItems { get; set; }
public int Score { get; set; }
+ public string StateObject { get; set; }
}
}
\ No newline at end of file
diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js
index cd853bc..ed7ee48 100644
--- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js
+++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js
@@ -1,6 +1,6 @@
///
-AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$location", "LabExerciseService",
-function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location, LabExerciseService) {
+AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$location", "LabExerciseService","AIAConstants",
+function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location, LabExerciseService,AIAConstants) {
$scope.$sce = $sce;
$scope.LabExerciseName;
$scope.LabExerciseQuiz = null;
@@ -138,6 +138,8 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location
$scope.Imagepath = keywords.labexercise + "/" + result.LabExercise[index].Questions[index1].ImagePath;
}
$scope.ShowHideDiv(result.LabExercise[index].Questions[index1].Options[0].textalign);
+
+ $scope.GetSavedLabExerciseFromDatabase();
}
});
//$scope.quiznumber++;
@@ -220,7 +222,6 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location
e.preventDefault();
e.stopPropagation();
var x = $("#droppable").offset();
- //alert(x.left + "," + $("#droppable").clientWidth + "," + x.top);
var id = $(this).attr("id");
@@ -229,6 +230,8 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location
var dataText = e.dataTransfer.getData('text/plain');
if (id == "divoptions" || id == "divleft" || id == "divright") {
+ alert('if')
+
var item = $('#' + $scope.dragableId).html();
var rindex = $scope.DraggedList.indexOf(item);
var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json';
@@ -271,7 +274,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location
)
}
else {
-
+ alert('else')
var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json';
DataService.getAnotherJson(labExerciseModulePath).then(
function (result) {
@@ -555,6 +558,76 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location
})
}
+
+ $scope.GetSavedLabExerciseFromDatabase = function () {
+
+ var labExerciseInfo = {
+ userId: 1,
+ identifier: 'di'
+ };
+
+ LabExerciseService.GetLabExercise(labExerciseInfo)
+ .then(
+
+ function (result) {
+ if (result != undefined && result != AIAConstants.SAVED_LAB_EXERCISE_NOT_FOUND) {
+ $scope.SavedLabExercise = result;
+
+ $scope.ShowSavedLabExercise();
+ }
+ },
+ function(error){
+ console.log(' Error in getting LabExercise = ' + error.statusText);
+ $rootScope.errorMessage = AdminConstants.ERROR_IN_FECTHING_DETAILS;
+ $("#messageModal").modal('show');
+ })
+
+ }
+
+ $scope.ShowSavedLabExercise = function () {
+
+ var lastQuestion = 1;//$scope.SavedLabExercise.lastQuestion;
+ var lastQuestionDetails = new jinqJs()
+ .from($scope.SavedLabExercise.labExercise)
+ .where('QuestionNo == ' + lastQuestion)
+ .select();
+
+ $scope.QustionAnsKeyValue =[];
+ var lastQuestionAnswers = lastQuestionDetails[0].UserAnswers.split(',');
+ for (var i = 0; i < lastQuestionAnswers.length; i++) {
+ var num = i + 1;
+ $scope.QustionAnsKeyValue.push({ blockbox: 'T' + num, text: lastQuestionAnswers[i] });
+
+ if (lastQuestionAnswers[i] != "") {
+ var blocks = $("div[id*='block-']");
+ for (var j = 0; j < blocks.length; j++) {
+
+ if ((blocks[j].innerHTML).toString() == lastQuestionAnswers[i]) {
+ $('#' + blocks[j].id).css("display", "none");
+ };
+ // userAnswers[id.replace('T', '')] = blockAnswers[i].innerHTML;
+ }
+
+ }
+ }
+
+
+ var labQuestionData = new jinqJs()
+ .from($scope.LabExData.LabExercise[0].Questions)
+ .where('Number == ' + lastQuestion)
+ .select();
+
+ angular.forEach($scope.QustionAnsKeyValue,function(value,key){
+ var questionOptionBox = new jinqJs()
+ .from(labQuestionData[0].OptionBox)
+ .where('BoxName == ' + value.blockbox)
+ .select();
+
+ $scope.DraggedList.push({ "id": 'blockbox-' + value.blockbox, "optionName": value.blockbox, "Value": value.text, "topcoord": questionOptionBox[0].topcoord, "leftcoord": questionOptionBox[0].leftcoord });
+
+ })
+
+ }
}]
);
diff --git a/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js b/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
index b1d2dd5..d340cdd 100644
--- a/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
+++ b/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
@@ -497,6 +497,8 @@ AIA.constant("AIAConstants", {
"NO_BODY_SYSTEM_AVAILABLE": "Selected body system is not available on this layer.",
"COOKIES_MESSAGE": "You need to enable your browser's cookies to run this application.",
"current_year": 2018,
+ "SAVED_LAB_EXERCISE_NOT_FOUND": "Saved Lab Exercise not found.",
+ "ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.",
})
diff --git a/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js
index 518d2e7..ee01b1e 100644
--- a/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js
+++ b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js
@@ -25,5 +25,29 @@
});
return deferred.promise;
},
+
+ GetLabExercise: function (labExerciseInfo) {
+ var deferred = $q.defer();
+
+
+ $http({
+ url: "/API/api/LabExercise",
+ method: "GET",
+ params: {userId:1, labExerciseIdentifier:'di'}
+ })
+
+ .success(function (data, status, headers, config) {
+ console.log('success')
+ deferred.resolve(data);
+ }).error(function (data, status, headers, config) {
+ console.log('error')
+ deferred.reject(data);
+ $rootScope.isVisibleLogin = true;
+ $rootScope.errorMessage = data;
+ $("#messageModal").modal('show');
+
+ });
+ return deferred.promise;
+ },
}
})
\ No newline at end of file