public IHttpActionResult ManageAnsOptions(JObject requestParams) { var data = ""; var identity = MyAuthorizationServerProvider.AuthenticateUser(); if (identity != null) { try { var compId = identity.CompId; var userId = identity.UserID; var answerId = 0; var title = ""; var isCorrect = false; var score = 0.0; var action = Convert.ToInt32(Convert.ToString(requestParams["Action"])); var contentTypeId = Convert.ToInt32(Convert.ToString(requestParams["ContentTypeID"])); var contentId = Convert.ToInt32(requestParams["ContentID"]); var questionId = Convert.ToInt32(requestParams["QuestionID"]); if (!string.IsNullOrEmpty(Convert.ToString(requestParams["AnswerID"]))) { answerId = Convert.ToInt32(requestParams["AnswerID"]); } if (action == 1 || action == 2) { title = Convert.ToString(requestParams["Title"]); isCorrect = false; if (!string.IsNullOrEmpty(Convert.ToString(requestParams["IsCorrect"]))) { isCorrect = Convert.ToBoolean(Convert.ToString(requestParams["IsCorrect"])); } if (contentTypeId == 5) { // Final Quiz score = Convert.ToDouble(Convert.ToString(requestParams["Score"])); // Numeric } } else if (action == 3) { } else if (action == 4) { } // CALL BL var ds = QuizBL.ManageAnsOptions(compId, userId, contentId, questionId, answerId, title, isCorrect, score, action); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows[0]["StatusCode"].ToString() == "1") { // Successful data = Utility.Successful(""); } else { // Error. Check Logs data = Utility.API_Status("1", "There might be some error. Please try again later"); } } else { // Unknown Error data = Utility.API_Status("1", "Unknown Error"); } } catch (Exception ex) { data = Utility.Exception(ex);; } } else { data = Utility.AuthenticationError(); } return(new APIResult(Request, data)); }
public IHttpActionResult ManageQuestion(JObject requestParams) { var data = ""; var identity = MyAuthorizationServerProvider.AuthenticateUser(); if (identity != null) { try { var compId = identity.CompId; var userId = identity.UserID; var questionId = 0; var isMandatory = true; var isMultiline = true; var contentId = 0; var title = ""; var qType = 0; var maxScore = 0.0; var isBox = false; var contentTypeId = Convert.ToInt32(Convert.ToString(requestParams["ContentTypeID"])); var action = Convert.ToInt32(Convert.ToString(requestParams["Action"])); var type = Convert.ToInt32(Convert.ToString(requestParams["Type"])); if (!string.IsNullOrEmpty(Convert.ToString(requestParams["QuestionID"]))) { questionId = Convert.ToInt32(requestParams["QuestionID"]); } if (!string.IsNullOrEmpty(Convert.ToString(requestParams["ContentID"]))) { contentId = Convert.ToInt32(requestParams["ContentID"]); } if (action == 1 || action == 2) { title = Convert.ToString(requestParams["Title"]); qType = Convert.ToInt32(Convert.ToString(requestParams["QType"])); // Numeric if (!string.IsNullOrEmpty(Convert.ToString(requestParams["IsBox"]))) { isBox = Convert.ToBoolean(Convert.ToString(requestParams["IsBox"])); } if (type == 1) { // Survey } else if (type == 2) { // Flashcards } else if (type == 3) { // Final Quiz maxScore = Convert.ToDouble(Convert.ToString(requestParams["MaxScore"])); } } else if (action == 3) { } else if (action == 4) { } // CALL BL var ds = QuizBL.ManageQuestion(compId, userId, questionId, contentId, isMandatory, isMultiline, title, qType, isBox, action); if (Convert.ToInt32(ds.Tables[0].Rows[0]["QuestionID"].ToString()) > 0 && (action == 1 || action == 2)) { questionId = Convert.ToInt32(ds.Tables[0].Rows[0]["QuestionID"].ToString()); for (int i = 0; i < requestParams["AnswerOptions"].Count(); i++) { bool isCorrect = false; double score = 0; var answerid = 0; if (!string.IsNullOrEmpty(Convert.ToString(requestParams["AnswerOptions"][i]["CorrectScore"]))) { score = Convert.ToInt32(requestParams["AnswerOptions"][i]["CorrectScore"]); } if (!string.IsNullOrEmpty(Convert.ToString(requestParams["AnswerOptions"][i]["AnswerID"]))) { answerid = Convert.ToInt32(requestParams["AnswerOptions"][i]["AnswerID"]); } if (!string.IsNullOrEmpty(Convert.ToString(requestParams["AnswerOptions"][i]["IsCorrect"]))) { isCorrect = Convert.ToBoolean(Convert.ToString(requestParams["AnswerOptions"][i]["IsCorrect"])); } var ds1 = QuizBL.ManageAnsOptions(compId, userId, contentId, questionId, answerid, Convert.ToString(requestParams["AnswerOptions"][i]["AnswerText"]), isCorrect, score, answerid > 0 ? 2 : 1); } } if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows[0]["StatusCode"].ToString() == "1") { // Successful data = Utility.Successful(""); } else { // Error. Check Logs data = Utility.API_Status("1", "There might be some error. Please try again later"); } } else { // Unknown Error data = Utility.API_Status("1", "Unknown Error"); } } catch (Exception ex) { data = Utility.Exception(ex);; } } else { data = Utility.AuthenticationError(); } return(new APIResult(Request, data)); }