示例#1
0
        //==========================================================//
        private bool IsValidate(SpeakingEmbedCombined SpeakingEmbedCombined)
        {
            if (!(SpeakingEmbedCombined != null && SpeakingEmbedCombined.TestCategory != null &&
                  SpeakingEmbedCombined.TestCategory.TypeCode != null && SpeakingEmbedCombined.TestCategory.TypeCode.Length > 0 &&
                  SpeakingEmbedCombined.TestCategory.PartId > 0 &&
                  SpeakingEmbedCombined.TestCategory.WYSIWYGContent != null && SpeakingEmbedCombined.TestCategory.WYSIWYGContent.Length > 0 &&
                  SpeakingEmbedCombined.SpeakingEmbed.YoutubeVideo != null &&
                  SpeakingEmbedCombined.SpeakingEmbed.YoutubeVideo.Length > 0))
            {
                return(false);
            }

            // Lấy mã người tạo
            int userId = User.Id();

            // Cập nhật mã người tạo cho category
            if (SpeakingEmbedCombined.TestCategory.CreatorId <= 0)
            {
                SpeakingEmbedCombined.TestCategory.CreatorId = userId;
            }

            if (SpeakingEmbedCombined.SpeakingEmbed.CreatorId <= 0)
            {
                SpeakingEmbedCombined.SpeakingEmbed.CreatorId = userId;
            }

            return(true);
        }
示例#2
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));
        }
示例#3
0
 public IActionResult EmbedCreate(SpeakingEmbedCombined SpeakingEmbedCombined)
 {
     return(EmbedProcessing(nameof(Embed), nameof(EmbedCreate), SpeakingEmbedCombined, false));
 }