private IActionResult Part1Or2Delete(int partId, long id) { ReadingPartOne readingPart1Question = null; ReadingPartTwo readingPart2Question = null; if (partId == 1) { readingPart1Question = _ReadingPartOneManager.Get(id); } if (partId == 2) { readingPart2Question = _ReadingPartTwoManager.Get(id); } bool isFound = (partId == 1 && readingPart1Question != null) || (partId == 2 && readingPart2Question != null); if (!isFound) { return(Json(new { success = false, responseText = "This question was not found." })); } if (partId == 1) { _ReadingPartOneManager.Delete(readingPart1Question); } if (partId == 2) { _ReadingPartTwoManager.Delete(readingPart2Question); } return(Json(new { success = true, id, responseText = "Deleted" })); }
public IActionResult Part4Create() { return(View($"{nameof(Part4)}/{nameof(Part4Create)}", new ReadingCombined { TestCategory = TestCategory.ReadingCategory(4), ReadingPartTwos = ReadingPartTwo.Generate(Config.MAX_READING_PART_4_QUESTION) })); }
public IActionResult Part2Create(ReadingPartTwo readingPartTwo) { if (readingPartTwo == null) { readingPartTwo = new ReadingPartTwo(); } ViewBag.TestCategories = _TestCategoryManager.GetAll(TestCategory.READING, 2) ?? new List <TestCategory>(); return(PartialView($"{nameof(Part2)}/{nameof(Part2Create)}", readingPartTwo)); }
private async Task <IActionResult> Part2Processing(ReadingPartTwo readingPartTwo, IFormFile questionImage) { // Kiểm tra tính hợp lệ string validateMsg = IsValidate(readingPartTwo.TestCategoryId, readingPartTwo.AnswerList, Config.MAX_READING_PART_2_QUESTION); if (!string.IsNullOrEmpty(validateMsg)) { return(Json(new { status = false, message = validateMsg })); } // Chuyển danh sách câu trả lời thành JSON để lưu trữ readingPartTwo.Answers = readingPartTwo.AnswerList.ToJson(); // Nếu dữ liệu không hợp lệ if (readingPartTwo.Answers == null || readingPartTwo.Answers.Length <= 0) { return(Json(new { status = false, message = "Unable to determine the answer to this question" })); } // Nếu chưa chọn ảnh cho mục này if (questionImage == null && readingPartTwo.Id <= 0) { return(Json(new { status = false, message = "Please select picture for the question." })); } // Cập nhật ảnh lên máy chủ string uploadResult = await host.UploadForTestImage(questionImage, TestCategory.READING, 2); if ((uploadResult == null || uploadResult.Length <= 0) && questionImage != null && questionImage.Length > 0) { return(Json(new { status = false, message = "Please check the picture of the question again" })); } // Nếu cập nhật ảnh thành công, lưu vào database if (uploadResult != null && uploadResult.Length > 0) { if (readingPartTwo.QuestionImage != null && readingPartTwo.QuestionImage.Length > 0) { host.RemoveUploadMeida(readingPartTwo.QuestionImage); } readingPartTwo.QuestionImage = uploadResult; } // Nếu chưa có người tạo if (readingPartTwo.CreatorId <= 0) { readingPartTwo.CreatorId = User.Id(); } // Nếu là tạo mới if (readingPartTwo.Id <= 0) { _ReadingPartTwoManager.Add(readingPartTwo); } else // Hoặc là cập nhật { _ReadingPartTwoManager.Update(readingPartTwo); } return(Json(new { status = true, message = "Successfully created, the list will refresh again in 1 second." })); }
public IActionResult Part4Update(long id) { if (id <= 0) { return(BadRequest()); } else { var testCategory = _TestCategoryManager.Get(id); if (testCategory == null) { return(NotFound()); } var readingPartTwos = _ReadingPartTwoManager.GetAll(testCategory.Id).ToList(); if (readingPartTwos.Count <= 0) { readingPartTwos = ReadingPartTwo.Generate(Config.MAX_READING_PART_4_QUESTION); } for (int i = 0; i < readingPartTwos.Count(); i++) { if (readingPartTwos[i].Answers != null && readingPartTwos[i].Answers.Length > 0) { try { readingPartTwos[i].AnswerList = JsonConvert.DeserializeObject <List <BaseAnswer> >(readingPartTwos[i].Answers); } catch (Exception) { } } } return(View($"{nameof(Part4)}/{nameof(Part4Update)}", new ReadingCombined { TestCategory = testCategory, ReadingPartTwos = readingPartTwos })); } }
public async Task <IActionResult> Part2UpdateAjax(ReadingPartTwo readingPartTwo, IFormFile questionImage) { return(await Part2Processing(readingPartTwo, questionImage)); }