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.Security.Service;
            using CloudBuilder.Core.DatabaseAccessor.Entity;
            using Microsoft.AspNetCore.Http;
            using CloudBuilder.Core.Policy;
            using CloudBuilder.Core.DependencyInjection.Request;
            using CloudBuilder.Security.Data;
            using CloudBuilder.Core.Authorization;
            using CloudBuilder.Security.Entity;
            using CloudBuilder.Security.SearchCriteria;
            using CloudBuilder.Security;
            using System;
            
namespace CloudBuilder.Web.Entry.Controllers.Security
{
[Authorize(AuthorizePolicy.PERMISSION)]
[ApiController]
[Route("[controller]/[action]")]
public class SecurityActorController : ControllerBase
{
private readonly IApplicationService service;
private readonly ISecurityActorService securityActorService;

public SecurityActorController(IApplicationService service, ISecurityActorService securityActorService)
{
this.service = service;
this.securityActorService= securityActorService;
}

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

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

                            [PermissionOperate(name: "SecurityActor", operate: "Find")]
                            [HttpPost]
                            public dynamic FindAll()
                    {
                    try
                    {

                    var result = securityActorService.FindAll();
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [AllowAnonymous]
                            [HttpPost]
                            public dynamic FindAllByNoPermission()
                    {
                    try
                    {

                    var result = securityActorService.FindAllByNoPermission();
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "SecurityActor", operate: "Find")]
                            [HttpPost]
                            public dynamic FindBySearchCriteria(SecurityActorSearchCriteria criteria)       
                    {
                    try
                    {            

                    var result = securityActorService.FindBySearchCriteria(criteria);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "SecurityActor", operate: "Print")]
                            [HttpPost]
                            public dynamic PrintBySearchCriteria(SecurityActorSearchCriteria criteria)       
                    {
                    try
                    {            

                    var result = securityActorService.PrintBySearchCriteria(criteria);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

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

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

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

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

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

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

                            [PermissionOperate(name: "SecurityActor", operate: "Delete")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Deletes(string[] keys){
                    try
                    {            
                securityActorService.Deletes(keys);

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

                    
}
}