コード例 #1
0
        public async Task <IActionResult> DeleteCategory(int categoryId)
        {
            if (!await _repo.CategoryExists(categoryId))
            {
                return(NotFound("Category does not exist!"));
            }

            var books = await _repo.GetBooksForCategory(categoryId);

            if (books.Count > 0)
            {
                ModelState.AddModelError("", "Category cannot be deleted because it is used by at least one author!");
                return(StatusCode(409, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await _work.Delete(await _repo.GetCategory(categoryId)))
            {
                ModelState.AddModelError("", "Something went wrong deleting country!!!");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
コード例 #2
0
        public void CreateWorkTest()
        {
            var work = new Work()
            {
                WorkID       = "Test000000",
                WorkContents = "測試內容",
                WorkName     = "測試用",
            };

            _work.Create(work);
            _work.Delete("Test000000");
            Assert.Pass();
        }
コード例 #3
0
 public void DeleteWork(string workID) => _work.Delete(workID);