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 SecurityGeneratorNumberController : ControllerBase
{
private readonly IApplicationService service;
private readonly ISecurityGeneratorNumberService securityGeneratorNumberService;

public SecurityGeneratorNumberController(IApplicationService service, ISecurityGeneratorNumberService securityGeneratorNumberService)
{
this.service = service;
this.securityGeneratorNumberService= securityGeneratorNumberService;
}

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

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

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

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

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

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

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

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

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

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

                            [PermissionOperate(name: "SecurityGeneratorNumber", operate: "Delete")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic Delete(Int32 key){
                    try
                    {            
                securityGeneratorNumberService.Delete(key);

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

                    
}
}