
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;
            using CloudBuilder.AI.SearchCriteria;
            using Microsoft.AspNetCore.Http;
            
namespace CloudBuilder.Web.Entry.Controllers.Ai
{
[Authorize(AuthorizePolicy.PERMISSION)]
[ApiController]
[Route("[controller]/[action]")]
public class DmsFileController : ControllerBase
{
private readonly IApplicationService service;
private readonly IDmsFileService dmsFileService;

public DmsFileController(IApplicationService service, IDmsFileService dmsFileService)
{
this.service = service;
this.dmsFileService= dmsFileService;
}

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

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

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

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

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic FindDatasBySearchCriteria(DmsFileSearchCriteria criteria)       
                    {
                    try
                    {            

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

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

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

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

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

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

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

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

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

                            [PermissionOperate(name: "DmsFile", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic GetFolderName(string folderLocalName)       
                    {
                    try
                    {            

                    var result = dmsFileService.GetFolderName(folderLocalName);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic CreateDmsFolder(DmsFileEntity dmsFile)       
                    {
                    try
                    {            

                    var result = dmsFileService.CreateDmsFolder(dmsFile);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Update")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic UpdateDmsFolder(DmsFileEntity dmsFile)       
                    {
                    try
                    {            

                    var result = dmsFileService.UpdateDmsFolder(dmsFile);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

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

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

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

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

                            [PermissionOperate(name: "DmsFile", operate: "Update")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic MoveDmsFolder(DmsFileEntity dmsFile){
                    try
                    {            
                dmsFileService.MoveDmsFolder(dmsFile);

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

                            [PermissionOperate(name: "DmsFile", operate: "Insert")]
                            [HttpPost]
                            [UnitOfWork]
                            public dynamic UploadFile()
                    {
                    try
                    {

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

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic DownloadFile(Int32 fileId)       
                    {
                    try
                    {            

                    var result = dmsFileService.DownloadFile(fileId);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic DownloadFilePreview(DmsFileEntity dmsFile)       
                    {
                    try
                    {            

                    var result = dmsFileService.DownloadFilePreview(dmsFile);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic DownloadFileCombine(string fileName)       
                    {
                    try
                    {            

                    var result = dmsFileService.DownloadFileCombine(fileName);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic FindDmsFolderMapByFolderName(string folderName)       
                    {
                    try
                    {            

                    var result = dmsFileService.FindDmsFolderMapByFolderName(folderName);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                            [PermissionOperate(name: "DmsFile", operate: "Find")]
                            [HttpPost]
                            public dynamic FindFolderNameParentByFolderName(string folderName)       
                    {
                    try
                    {            

                    var result = dmsFileService.FindFolderNameParentByFolderName(folderName);
                    return result;
                    }
                    catch (ValidatedException vex)
                    {
                    return vex;
                    }            
                    catch (Exception ex)
                    {
                    return new ServiceErrorException(ex);
                    }           
                    }

                    
}
}