LabExerciseController.cs
5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using log4net;
using AIAHTML5.API.Constants;
using AIAHTML5.API.Models;
using System.Collections;
using System.Data.SqlClient;
namespace AIAHTML5.API.Controllers
{
public class LabExerciseController : ApiController
{
// GET api/authenticate
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/authenticate/5
public string Get(int id)
{
return "value";
}
// POST api/authenticate
public HttpResponseMessage Post([FromBody]JArray labExerciseUserAttemptData)
{
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug("inside insertLabExerciseAttempt Post LabExerciseController");
try
{
LabExercise le = new LabExercise();
le.labExercise = new List<LabEcerciseDetails>();
foreach (var item in labExerciseUserAttemptData.Children())
{
var itemProperties = item.Children<JProperty>();
//you could do a foreach or a linq here depending on what you need to do exactly with the value
var userId = itemProperties.FirstOrDefault(x => x.Name == "userId");
le.userId = Convert.ToInt32(userId.Value); ////This is a JValue type
var labExerciseIdentifier = itemProperties.FirstOrDefault(x => x.Name == "labExerciseIdentifier");
le.labExerciseIdentifier = labExerciseIdentifier.Value.ToString(); ////This is a JValue type
var lastQuestion = itemProperties.FirstOrDefault(x => x.Name == "LastQuestion");
le.lastQuestion = Convert.ToInt32(lastQuestion.Value); ////This is a JValue type
var totalQuestions = itemProperties.FirstOrDefault(x => x.Name == "TotalQuestions");
le.totalQuestions = Convert.ToInt32(totalQuestions.Value); ////This is a JValue type
var LabExerciseUserData = itemProperties.FirstOrDefault(x => x.Name == "LabExerciseUserData");
foreach (var labQuiz in LabExerciseUserData.Children())
{
var labQuizProperties = labQuiz.Children();
foreach (var lb in labQuizProperties)
{
var itemProperties1 = lb.Children<JProperty>();
LabEcerciseDetails labExDetails = new LabEcerciseDetails();
var MaxScore = itemProperties1.FirstOrDefault(x => x.Name == "MaxScore");
labExDetails.MaxScore = Convert.ToInt32(MaxScore.Value);
var UserAnswer = itemProperties1.FirstOrDefault(x => x.Name == "UserAnswer");
labExDetails.UserAnswer = UserAnswer.Value.ToString();
var QuestionNo = itemProperties1.FirstOrDefault(x => x.Name == "QuestionNo");
labExDetails.QuestionNo = Convert.ToInt32(QuestionNo.Value);
var CorrectAnswer = itemProperties1.FirstOrDefault(x => x.Name == "CorrectAnswer");
labExDetails.CorrectAnswer = CorrectAnswer.Value.ToString();
var DragItems = itemProperties1.FirstOrDefault(x => x.Name == "DragItems");
labExDetails.DragItems = DragItems.Value.ToString();
var Score = itemProperties1.FirstOrDefault(x => x.Name == "Score");
labExDetails.Score = Convert.ToInt32(Score.Value);
le.labExercise.Add(labExDetails);
}
}
}
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("insertyed") };
}
catch (SqlException e)
{
//logger.Fatal("SqlException occured for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "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.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) };
}
catch (Exception e)
{
//logger.Fatal("Exception occured for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
//ArrayList supportMailList = UserUtility.GetSupportMailList();
//string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT;
//string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
//UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.EXCEPTION_OCCURED) };
}
}
// PUT api/authenticate/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/authenticate/5
public void Delete(int id)
{
}
}
}