public IActionResult UpdateAjax(TestCategory testCategory)
        {
            if (ModelState.IsValid)
            {
                _TestCategoryManager.Update(testCategory);
                return(Json(new { status = true, message = "Successfully updated, the list will refresh again in 1 second." }));
            }
            else
            {
                string errors = "";
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        if (errors.Length > 0)
                        {
                            errors += "\r\n";
                        }
                        errors += error.ErrorMessage;
                    }
                }

                return(Json(new { status = false, message = errors }));
            }
        }
예제 #2
0
 private bool UpdateTestCategory(ListeningBaseCombined listeningBaseCombined)
 {
     if (listeningBaseCombined.TestCategory.Id <= 0)
     {
         _TestCategoryManager.Add(listeningBaseCombined.TestCategory);
     }
     else
     {
         _TestCategoryManager.Update(listeningBaseCombined.TestCategory);
     }
     return(listeningBaseCombined.TestCategory.Id > 0);
 }
예제 #3
0
        private IActionResult EmbedProcessing(string partName, string partAction, SpeakingEmbedCombined SpeakingEmbedCombined, bool isCheckQuestionText = true)
        {
            var view = View($"{partName}/{partAction}", SpeakingEmbedCombined);

            // Nếu không hợp lệ
            if (!IsValidate(SpeakingEmbedCombined))
            {
                ModelState.AddModelError(string.Empty, "Please enter the full information of the required item");
                return(view);
            }

            // Tiến hành thêm danh mục vào CSDL và lấy ID
            if (SpeakingEmbedCombined.TestCategory.Id <= 0)
            {
                _TestCategoryManager.Add(SpeakingEmbedCombined.TestCategory);
            }
            else
            {
                _TestCategoryManager.Update(SpeakingEmbedCombined.TestCategory);
            }

            if (SpeakingEmbedCombined.TestCategory.Id <= 0)
            {
                ModelState.AddModelError(string.Empty, "An error occurred during execution.");
                return(view);
            }

            // Cập nhật ID danh mục cho bài viết 2
            if (SpeakingEmbedCombined.SpeakingEmbed.TestCategoryId <= 0)
            {
                SpeakingEmbedCombined.SpeakingEmbed.TestCategoryId = SpeakingEmbedCombined.TestCategory.Id;
            }

            // Kiểm tra và cập nhật vào CSDL
            if (SpeakingEmbedCombined.SpeakingEmbed.Id <= 0)
            {
                _SpeakingEmbedManager.Add(SpeakingEmbedCombined.SpeakingEmbed);
            }
            else
            {
                _SpeakingEmbedManager.Update(SpeakingEmbedCombined.SpeakingEmbed);
            }

            this.NotifySuccess("Update completed!");

            // Trả về
            return(RedirectToAction(partName));
        }
        private IActionResult Part3Or4Processing(string partName, string partAction, ReadingCombined readingCombined, bool isCheckQuestionText = true)
        {
            var view = View($"{partName}/{partAction}", readingCombined);

            // Nếu không hợp lệ
            if (!IsValidate(readingCombined, isCheckQuestionText))
            {
                return(view);
            }

            // Tiến hành thêm danh mục vào CSDL và lấy ID
            if (readingCombined.TestCategory.Id <= 0)
            {
                _TestCategoryManager.Add(readingCombined.TestCategory);
            }
            else
            {
                _TestCategoryManager.Update(readingCombined.TestCategory);
            }

            if (readingCombined.TestCategory.Id <= 0)
            {
                ModelState.AddModelError(string.Empty, "An error occurred during execution.");
                return(view);
            }

            // Cập nhật câu hỏi
            for (int i = 0; i < readingCombined.ReadingPartTwos.Count; i++)
            {
                if (readingCombined.ReadingPartTwos[i].TestCategoryId <= 0)
                {
                    readingCombined.ReadingPartTwos[i].TestCategoryId = readingCombined.TestCategory.Id;
                }
                if (readingCombined.ReadingPartTwos[i].Id <= 0)
                {
                    _ReadingPartTwoManager.Add(readingCombined.ReadingPartTwos[i]);
                }
                else
                {
                    _ReadingPartTwoManager.Update(readingCombined.ReadingPartTwos[i]);
                }
            }

            this.NotifySuccess("Update completed!");

            // Trả về
            return(RedirectToAction(partName));
        }