
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;
            
namespace CloudBuilder.Web.Entry.Controllers.Ai
{
[Authorize(AuthorizePolicy.PERMISSION)]
[ApiController]
[Route("[controller]/[action]")]
public class AiBookPersonController : ControllerBase
{
private readonly IApplicationService service;
private readonly IAiBookPersonService aiBookPersonService;

public AiBookPersonController(IApplicationService service, IAiBookPersonService aiBookPersonService)
{
this.service = service;
this.aiBookPersonService= aiBookPersonService;
}

        [PermissionOperate(name: "AiBookPerson", operate: "Find")]
                            [HttpPost]
                            public dynamic FindByKey(string key)       
                    {
                    try
                    {            

                    var result = aiBookPersonService.FindByKey(key);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBookPerson", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Insert(AiBookPersonEntity data)       
                    {
                    try
                    {            

                    var result = aiBookPersonService.Insert(data);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBookPerson", operate: "Update")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Update(AiBookPersonEntity data)       
                    {
                    try
                    {            

                    var result = aiBookPersonService.Update(data);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "AiBookPerson", operate: "Delete")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Delete(string key){
                    try
                    {            
                aiBookPersonService.Delete(key);

                    return string.Empty;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }                    
                    }

                    
}
}