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" }));
        }
        private IActionResult Part1Processing(ReadingPartOne readingPartOne)
        {
            // Kiểm tra tính hợp lệ
            string validateMsg = IsValidate(readingPartOne.TestCategoryId, readingPartOne.AnswerList, Config.MAX_READING_PART_1_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ữ
            readingPartOne.Answers = readingPartOne.AnswerList.ToJson();
            // Nếu dữ liệu không hợp lệ
            if (readingPartOne.Answers == null || readingPartOne.Answers.Length <= 0)
            {
                return(Json(new { status = false, message = "Unable to determine the answer to this question" }));
            }
            // Nếu chưa có người tạo
            if (readingPartOne.CreatorId <= 0)
            {
                readingPartOne.CreatorId = User.Id();
            }
            // Nếu là thêm mới
            if (readingPartOne.Id <= 0)
            {
                _ReadingPartOneManager.Add(readingPartOne);
            }
            else // Còn không là cập nhật
            {
                _ReadingPartOneManager.Update(readingPartOne);
            }
            // Trả về kết quả thành công
            return(Json(new { status = true, message = "Successfully created, the list will refresh again in 1 second." }));
        }
Exemplo n.º 3
0
 public IActionResult Part1Create(ReadingPartOne readingPartOne)
 {
     if (readingPartOne == null)
     {
         readingPartOne = new ReadingPartOne();
     }
     ViewBag.TestCategories = _TestCategoryManager.GetAll(TestCategory.READING, 1) ?? new List <TestCategory>();
     return(PartialView($"{nameof(Part1)}/{nameof(Part1Create)}", readingPartOne));
 }
Exemplo n.º 4
0
 public IActionResult Part1UpdateAjax(ReadingPartOne readingPartOne)
 {
     return(Part1Processing(readingPartOne));
 }