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 AiParagraphController : ControllerBase { private readonly IApplicationService service; private readonly IAiParagraphService aiParagraphService; public AiParagraphController(IApplicationService service, IAiParagraphService aiParagraphService) { this.service = service; this.aiParagraphService= aiParagraphService; } [PermissionOperate(name: "AiParagraph", operate: "Find")] [HttpPost] public dynamic FindByKey(string key) { try { var result = aiParagraphService.FindByKey(key); return result; } catch (ValidatedException vex) { return vex; } catch (Exception ex) { return new ServiceErrorException(ex); } } [PermissionOperate(name: "AiParagraph", operate: "Insert")] [HttpPost] [UnitOfWork] public dynamic Insert(AiParagraphEntity data) { try { var result = aiParagraphService.Insert(data); return result; } catch (ValidatedException vex) { return vex; } catch (Exception ex) { return new ServiceErrorException(ex); } } [PermissionOperate(name: "AiParagraph", operate: "Insert")] [HttpPost] [UnitOfWork] public dynamic Inserts(AiParagraphEntity[] datas){ try { aiParagraphService.Inserts(datas); return string.Empty; } catch (ValidatedException vex) { return vex; } catch (Exception ex) { return new ServiceErrorException(ex); } } [PermissionOperate(name: "AiParagraph", operate: "Update")] [HttpPost] [UnitOfWork] public dynamic Update(AiParagraphEntity data) { try { var result = aiParagraphService.Update(data); return result; } catch (ValidatedException vex) { return vex; } catch (Exception ex) { return new ServiceErrorException(ex); } } [PermissionOperate(name: "AiParagraph", operate: "Delete")] [HttpPost] [UnitOfWork] public dynamic Delete(string key){ try { aiParagraphService.Delete(key); return string.Empty; } catch (ValidatedException vex) { return vex; } catch (Exception ex) { return new ServiceErrorException(ex); } } } }