556 lines
21 KiB
C#
556 lines
21 KiB
C#
|
|
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.Master.Service;
|
|
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using CloudBuilder.Master.Data;
|
|
using System;
|
|
using CloudBuilder.Master.SearchCriteria;
|
|
using Microsoft.AspNetCore.Http;
|
|
using CloudBuilder.Master.Entity;
|
|
|
|
namespace CloudBuilder.Web.Entry.Controllers.Master
|
|
{
|
|
[Authorize(AuthorizePolicy.PERMISSION)]
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class FamilyTreeController : ControllerBase
|
|
{
|
|
private readonly IApplicationService service;
|
|
private readonly IFamilyTreeService familyTreeService;
|
|
|
|
public FamilyTreeController(IApplicationService service, IFamilyTreeService familyTreeService)
|
|
{
|
|
this.service = service;
|
|
this.familyTreeService= familyTreeService;
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindAllByTreeId(string treeId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.FindAllByTreeId(treeId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindByKey(string key)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.FindByKey(key);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class FindByCurrentPersonCompositionData
|
|
{
|
|
public string key { get; set; }
|
|
public string personId { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindByCurrentPerson(FindByCurrentPersonCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.FindByCurrentPerson(compositionData.key,compositionData.personId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FindBySearchCriteria(FamilyTreeSearchCriteria criteria)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.FindBySearchCriteria(criteria);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Insert")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Insert(FamilyTreeData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.Insert(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class RequestFamilyTreePermissionCompositionData
|
|
{
|
|
public string treeId { get; set; }
|
|
public string currentPersonId { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic RequestFamilyTreePermission(RequestFamilyTreePermissionCompositionData compositionData){
|
|
try
|
|
{
|
|
familyTreeService.RequestFamilyTreePermission(compositionData.treeId,compositionData.currentPersonId);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class ApproveFamilyTreePermissionCompositionData
|
|
{
|
|
public string treeId { get; set; }
|
|
public string currentPersonId { get; set; }
|
|
public string userName { get; set; }
|
|
public string managerIndc { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic ApproveFamilyTreePermission(ApproveFamilyTreePermissionCompositionData compositionData){
|
|
try
|
|
{
|
|
familyTreeService.ApproveFamilyTreePermission(compositionData.treeId,compositionData.currentPersonId,compositionData.userName,compositionData.managerIndc);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class RejectFamilyTreePermissionCompositionData
|
|
{
|
|
public string treeId { get; set; }
|
|
public string currentPersonId { get; set; }
|
|
public string userName { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic RejectFamilyTreePermission(RejectFamilyTreePermissionCompositionData compositionData){
|
|
try
|
|
{
|
|
familyTreeService.RejectFamilyTreePermission(compositionData.treeId,compositionData.currentPersonId,compositionData.userName);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class BindSelfPersonCompositionData
|
|
{
|
|
public string treeId { get; set; }
|
|
public string personId { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic BindSelfPerson(BindSelfPersonCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.BindSelfPerson(compositionData.treeId,compositionData.personId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic UnbindSelfPerson(string treeId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.UnbindSelfPerson(treeId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Update(FamilyTreeData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.Update(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Delete")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Delete(string key){
|
|
try
|
|
{
|
|
familyTreeService.Delete(key);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Delete")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Deletes(string[] keys){
|
|
try
|
|
{
|
|
familyTreeService.Deletes(keys);
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic GetExchangeFactor()
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.GetExchangeFactor();
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class ExportFamilyTreeCompositionData
|
|
{
|
|
public string treeId { get; set; }
|
|
public string scope { get; set; }
|
|
public string anchorPersonId { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic ExportFamilyTree(ExportFamilyTreeCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ExportFamilyTree(compositionData.treeId,compositionData.scope,compositionData.anchorPersonId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class SaveExchangeFileCompositionData
|
|
{
|
|
public string fileName { get; set; }
|
|
public string contentBase64 { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic SaveExchangeFile(SaveExchangeFileCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.SaveExchangeFile(compositionData.fileName,compositionData.contentBase64);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic ListExchangeFiles(string treeId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ListExchangeFiles(treeId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic ReadExchangeFile(string fileName)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ReadExchangeFile(fileName);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class ImportFamilyTreeCompositionData
|
|
{
|
|
public string targetTreeId { get; set; }
|
|
public FamilyTreeExchangeData data { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic ImportFamilyTree(ImportFamilyTreeCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ImportFamilyTree(compositionData.targetTreeId,compositionData.data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class ImportSubTreeCompositionData
|
|
{
|
|
public string targetTreeId { get; set; }
|
|
public string anchorPersonId { get; set; }
|
|
public FamilyTreeExchangeData data { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic ImportSubTree(ImportSubTreeCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ImportSubTree(compositionData.targetTreeId,compositionData.anchorPersonId,compositionData.data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "FamilyTree", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic ListBackups(string treeId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.ListBackups(treeId);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
public class RestoreBackupCompositionData
|
|
{
|
|
public string targetTreeId { get; set; }
|
|
public string backupFileName { get; set; }
|
|
|
|
}
|
|
[PermissionOperate(name: "FamilyTree", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic RestoreBackup(RestoreBackupCompositionData compositionData)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = familyTreeService.RestoreBackup(compositionData.targetTreeId,compositionData.backupFileName);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |