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()); }
public void CreateWorkTest() { var work = new Work() { WorkID = "Test000000", WorkContents = "測試內容", WorkName = "測試用", }; _work.Create(work); _work.Delete("Test000000"); Assert.Pass(); }
public void DeleteWork(string workID) => _work.Delete(workID);