docs: api for deleting a category

This commit is contained in:
Hamid Reza Mohammadi 2022-03-28 13:15:01 +04:30
parent 40575e6fa6
commit e0f5927c81
4 changed files with 78 additions and 0 deletions

View File

@ -541,6 +541,26 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
/// <summary>
/// delete a category
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete]
[Route("cat/{id}")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> DeleteCategoryAsync(int id)
{
var res = await _ganjoorService.DeleteCategoryAsync(id);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();
}
/// <summary>
/// Start Finding Missing Rhythms
/// </summary>

View File

@ -997,6 +997,13 @@
<param name="rhythm"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.DeleteCategoryAsync(System.Int32)">
<summary>
delete a category
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.StartFindingMissingRhythms(System.Boolean,System.Int32)">
<summary>
Start Finding Missing Rhythms
@ -11389,6 +11396,13 @@
<param name="rejectionCause"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.DeleteCategoryAsync(System.Int32)">
<summary>
delete a category
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.SetCategoryLanguageTag(System.Int32,System.String)">
<summary>
set category poems language tag
@ -13643,6 +13657,13 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteCategoryAsync(System.Int32)">
<summary>
delete a category
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.ChangePoetImageAsync(System.Int32,System.Guid)">
<summary>
chaneg poet image

View File

@ -840,6 +840,13 @@ namespace RMuseum.Services
/// <returns></returns>
Task<RServiceResult<bool>> RejectPoetSuggestedSpecLinesAsync(int id, Guid deleteUserId, string rejectionCause);
/// <summary>
/// delete a category
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<RServiceResult<bool>> DeleteCategoryAsync(int id);
/// <summary>
/// set category poems language tag
/// </summary>

View File

@ -2889,6 +2889,36 @@ namespace RMuseum.Services.Implementation
}
}
/// <summary>
/// delete a category
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> DeleteCategoryAsync(int id)
{
try
{
if(true == await _context.GanjoorPoems.Where(p => p.CatId == id).AnyAsync())
{
return new RServiceResult<bool>(false, "cat has poems!");
}
var page = await _context.GanjoorPages.Where(p => p.GanjoorPageType == GanjoorPageType.CatPage && p.CatId == id).SingleAsync();
_context.Remove(page);
await _context.SaveChangesAsync();
var cat = await _context.GanjoorCategories.Where(c => c.Id == id).SingleAsync();
_context.Remove(cat);
await _context.SaveChangesAsync();
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// chaneg poet image
/// </summary>