#400 book CRUD
This commit is contained in:
parent
dc26f01753
commit
f4683e872f
@ -430,7 +430,7 @@ namespace RMuseum.Controllers
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<PDFBook>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetByTagValue(string tagUrl, string valueUrl)
|
||||
public async Task<IActionResult> GetByTagValueAsync(string tagUrl, string valueUrl)
|
||||
{
|
||||
RServiceResult<PDFBook[]> itemsInfo = await _pdfService.GetPDFBookByTagValueAsync(tagUrl, valueUrl, new PublishStatus[] { PublishStatus.Published });
|
||||
if (!string.IsNullOrEmpty(itemsInfo.ExceptionString))
|
||||
@ -472,6 +472,40 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// update book
|
||||
/// </summary>
|
||||
/// <param name="book"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("book")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> UpdateBookAsync([FromBody] Book book)
|
||||
{
|
||||
var res = await _pdfService.UpdateBookAsync(book);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete book
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("book")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.DeleteOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> DeleteBookAsync(int id)
|
||||
{
|
||||
var res = await _pdfService.DeleteBookAsync(id);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get authors
|
||||
/// </summary>
|
||||
@ -561,7 +595,7 @@ namespace RMuseum.Controllers
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPut("author")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.AddOperationShortName)]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> UpdateAuthorAsync([FromBody] Author author)
|
||||
@ -579,7 +613,7 @@ namespace RMuseum.Controllers
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpDelete("author/{id}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.AddOperationShortName)]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.DeleteOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> DeleteAuthorAsync(int id)
|
||||
@ -591,7 +625,7 @@ namespace RMuseum.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("pdfbook/{pdfBookId}/contributor")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.AddOperationShortName)]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> AddPDFBookContributerAsync(int pdfBookId, [FromBody] AuthorRole role)
|
||||
@ -611,7 +645,7 @@ namespace RMuseum.Controllers
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpDelete("pdfbook/{pdfBookId}/contributor/{contributorRecordId}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.AddOperationShortName)]
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> DeletePDFBookContributerAsync(int pdfBookId, int contributorRecordId)
|
||||
@ -683,7 +717,7 @@ namespace RMuseum.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add a new mukti volume pdf collection
|
||||
/// add a new multi volume pdf collection
|
||||
/// </summary>
|
||||
/// <param name="volumes"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@ -2431,7 +2431,7 @@
|
||||
<param name="tagValueId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetByTagValue(System.String,System.String)">
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetByTagValueAsync(System.String,System.String)">
|
||||
<summary>
|
||||
get tagged publish pdfbooks (including CoverImage info but not pages or tagibutes info)
|
||||
</summary>
|
||||
@ -2446,6 +2446,20 @@
|
||||
<param name="book"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.UpdateBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
update book
|
||||
</summary>
|
||||
<param name="book"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.DeleteBookAsync(System.Int32)">
|
||||
<summary>
|
||||
delete book
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetAuthorsAsync(RSecurityBackend.Models.Generic.PagingParameterModel,System.String)">
|
||||
<summary>
|
||||
get authors
|
||||
@ -2508,7 +2522,7 @@
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.AddMultiVolumePDFCollection(RMuseum.Models.PDFLibrary.MultiVolumePDFCollection)">
|
||||
<summary>
|
||||
add a new mukti volume pdf collection
|
||||
add a new multi volume pdf collection
|
||||
</summary>
|
||||
<param name="volumes"></param>
|
||||
<returns></returns>
|
||||
@ -17788,6 +17802,20 @@
|
||||
<param name="book"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.UpdateBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
update book
|
||||
</summary>
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.DeleteBookAsync(System.Int32)">
|
||||
<summary>
|
||||
delete book
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.AddMultiVolumePDFCollection(RMuseum.Models.PDFLibrary.MultiVolumePDFCollection)">
|
||||
<summary>
|
||||
add multi volume pdf collection
|
||||
@ -18731,6 +18759,20 @@
|
||||
<param name="book"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.UpdateBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
update book
|
||||
</summary>
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.DeleteBookAsync(System.Int32)">
|
||||
<summary>
|
||||
delete book
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.AddMultiVolumePDFCollection(RMuseum.Models.PDFLibrary.MultiVolumePDFCollection)">
|
||||
<summary>
|
||||
add multi volume pdf collection
|
||||
|
||||
@ -146,6 +146,20 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<Book>> AddBookAsync(Book book);
|
||||
|
||||
/// <summary>
|
||||
/// update book
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<Book>> UpdateBookAsync(Book model);
|
||||
|
||||
/// <summary>
|
||||
/// delete book
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteBookAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// add multi volume pdf collection
|
||||
/// </summary>
|
||||
|
||||
@ -629,6 +629,7 @@ namespace RMuseum.Services.Implementation
|
||||
dbAuthor.Bio = model.Bio;
|
||||
dbAuthor.ImageId = model.ImageId;
|
||||
dbAuthor.ExtenalImageUrl = model.ExtenalImageUrl;
|
||||
dbAuthor.LastModified = DateTime.Now;
|
||||
_context.Update(dbAuthor);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<Author>(model);
|
||||
@ -860,6 +861,52 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// update book
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<Book>> UpdateBookAsync(Book model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbBook = await _context.Books.Where(b => b.Id == model.Id).SingleAsync();
|
||||
dbBook.Name = model.Name;
|
||||
dbBook.Description = model.Description;
|
||||
dbBook.CoverImageId = model.CoverImageId;
|
||||
dbBook.ExtenalCoverImageUrl = model.ExtenalCoverImageUrl;
|
||||
dbBook.LastModified = DateTime.Now;
|
||||
|
||||
_context.Update(model);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<Book>(model);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<Book>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete book
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteBookAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbBook = await _context.Books.Where(b => b.Id == id).SingleAsync();
|
||||
_context.Books.Remove(dbBook);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// add multi volume pdf collection
|
||||
|
||||
Loading…
Reference in New Issue
Block a user