Exemplo n.º 1
0
        private async Task <bool> UpdateAudio(ListeningBaseCombined listeningBaseCombined, IFormFile audio)
        {
            if ((audio == null || audio.Length <= 0) && listeningBaseCombined.TestCategory.Id > 0)
            {
                return(true);
            }

            // Tiến hành tải audio lên
            string audioUploadPath = await host.UploadForTestAudio(audio, TestCategory.LISTENING, listeningBaseCombined.TestCategory.PartId);

            if (audioUploadPath == null || audioUploadPath.Length <= 0)
            {
                // Nếu gặp sự cố thì tiến hành xóa bỏ mục câu hỏi và trở lại trang thêm để thông báo
                if (listeningBaseCombined.ListeningMedia.Id <= 0)
                {
                    _TestCategoryManager.Delete(listeningBaseCombined.TestCategory);
                }
                ModelState.AddModelError(string.Empty, "Cannot upload audio file.");
                return(false);
            }
            else
            {
                // Cập nhật đường dẫn vào
                listeningBaseCombined.ListeningMedia.Audio = audioUploadPath;
                // Cập nhật mục nó thuộc về
                if (listeningBaseCombined.ListeningMedia.TestCategoryId <= 0)
                {
                    listeningBaseCombined.ListeningMedia.TestCategoryId = listeningBaseCombined.TestCategory.Id;
                    listeningBaseCombined.ListeningMedia.Active         = true;
                    // Cập nhật vào CSDl
                    _ListeningMediaManager.Add(listeningBaseCombined.ListeningMedia);
                }
                else
                {
                    // Cập nhật vào CSDl
                    _ListeningMediaManager.Update(listeningBaseCombined.ListeningMedia);
                }
            }

            return(true);
        }
        public IActionResult Delete(long id)
        {
            var testCategory = _TestCategoryManager.Get(id);

            if (testCategory == null)
            {
                return(Json(new { success = false, responseText = "This category was not found." }));
            }
            else
            {
                _TestCategoryManager.Delete(testCategory);
                return(Json(new { success = true, user = JsonConvert.SerializeObject(testCategory), responseText = "Deleted" }));
            }
        }
Exemplo n.º 3
0
        private IActionResult EmbedDelele(int partId, long id)
        {
            var category = _TestCategoryManager.Get(id);

            if (category.TypeCode != TestCategory.SPEAKING || category.PartId != partId)
            {
                return(Json(new { success = false, responseText = "You cannot perform deletion to item other than the current item." }));
            }
            if (category == null)
            {
                return(Json(new { success = false, responseText = "This category was not found." }));
            }
            else
            {
                _TestCategoryManager.Delete(category);
                return(Json(new { success = true, category = JsonConvert.SerializeObject(category), responseText = "Deleted" }));
            }
        }