public ActionResult Create(CreateTaskItemDetailJson taskItemDetail) { try { int taskId = taskItemDetail.taskId; int totalScore = taskItemDetail.totalScore; var categories = taskItemDetail.categories; TaskManager.UpdateTotalScore(taskId, totalScore); foreach (var category in categories) { var categoryId = category.categoryId; // Insert to TaskCategory Table. Get TaskCategoryId PK. Return 0, if record exists int taskCategoryId = TaskManager.AddTaskCategory(taskId, categoryId); var questionAnswerDetails = category.questionAnswerDetails; if (questionAnswerDetails != null) { for (int i = 0; i < questionAnswerDetails.Length; i++) { var questionAnswerDetail = questionAnswerDetails[i]; if (questionAnswerDetail != null) { int questionId = questionAnswerDetail.questionId; int answerId = questionAnswerDetail.answerId; //int weightId = TaskManager.GetWeightIdByValue(questionAnswerDetail.weightValue); int multiplierId = questionAnswerDetail.multiplierId; int score = questionAnswerDetail.score; // Insert to Category_Question_Answer Table TaskManager.AddCategoryQuestionAnswer(taskCategoryId, questionId, answerId, multiplierId, score); } } } } var redirectUrl = new UrlHelper(Request.RequestContext).Action("Details", "TaskItemDetail", new { id = taskId, created = true }); return(Json(new { message = "Success", Url = redirectUrl })); } catch { return(View()); } }