154 lines
5.1 KiB
C#
154 lines
5.1 KiB
C#
|
|
using CloudBuilder.Core.DatabaseAccessor;
|
|
using CloudBuilder.Core.Policy;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Transactions;
|
|
using CloudBuilder.Core.Service;
|
|
using CloudBuilder.AI.Service;
|
|
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using CloudBuilder.AI.Entity;
|
|
using System;
|
|
using CloudBuilder.AI.Data;
|
|
|
|
namespace CloudBuilder.Web.Entry.Controllers.Ai
|
|
{
|
|
[Authorize(AuthorizePolicy.PERMISSION)]
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class AiBookController : ControllerBase
|
|
{
|
|
private readonly IApplicationService service;
|
|
private readonly IAiBookService aiBookService;
|
|
|
|
public AiBookController(IApplicationService service, IAiBookService aiBookService)
|
|
{
|
|
this.service = service;
|
|
this.aiBookService= aiBookService;
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindByKey(string key)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = aiBookService.FindByKey(key);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindByTitle(string title)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = aiBookService.FindByTitle(title);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Insert")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Insert(AiBookEntity data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = aiBookService.Insert(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Insert")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Insert(AiBookData data){
|
|
try
|
|
{
|
|
aiBookService.Insert(data);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Update(AiBookEntity data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = aiBookService.Update(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "AiBook", operate: "Delete")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Delete(string key){
|
|
try
|
|
{
|
|
aiBookService.Delete(key);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |