94 lines
3.5 KiB
C#
94 lines
3.5 KiB
C#
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.IServices;
|
|
using APT.Infrastructure.Core;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using APT.Utility;
|
|
using APT.Infrastructure.Api;
|
|
using APT.Migrations;
|
|
using APT.BaseData.Domain.Entities.OP;
|
|
using APT.BaseData.Domain.Enums.OP;
|
|
|
|
namespace APT.PF.WebApiControllers.Api.PF
|
|
{
|
|
[Route("api/PF/PFHomeTitle")]
|
|
public class PFHomeTitleController : AuthorizeApiController<T_PF_HOME_TITLE>
|
|
{
|
|
|
|
/// <summary>
|
|
/// 更新或新增数据
|
|
/// </summary>
|
|
/// <param name="entity">对象实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_PF_HOME_TITLE entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
//如果是总部 同步修改 子公司
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
UpdateEntityNoCommit(entity);
|
|
});
|
|
|
|
try
|
|
{
|
|
if (entity.ISTOCHILE)
|
|
{
|
|
#region 总部
|
|
|
|
Dictionary<Guid, string> dicORGCONN = new Dictionary<Guid, string>();
|
|
string conn = string.Empty;
|
|
IEnumerable<T_OP_TENANT> listTent = null;
|
|
using (var context = new MigrationContext())
|
|
{
|
|
listTent = context.GetEntities<T_OP_TENANT>(e => e.DB_CONN_ID.HasValue && e.ID != entity.ORG_ID, null, null);
|
|
List<Guid> listConnID = listTent.Select(e => e.DB_CONN_ID.Value).ToList();
|
|
var listDbConn = context.GetEntities<T_OP_TENANT_DB_CONN>(e => listConnID.Contains(e.ID), null, null);
|
|
foreach (var item in listDbConn)
|
|
{
|
|
conn = item.DB_CONN;
|
|
if (ConfigurationManager.AppSettings["Env"] == ((int)EnvType.外网).ToString())
|
|
{
|
|
conn = item.DB_CONN_WAN;
|
|
}
|
|
if (!dicORGCONN.ContainsKey(item.ID))
|
|
{
|
|
dicORGCONN.Add(listTent.First(e => e.DB_CONN_ID == item.ID).ID, conn);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var itemConn in dicORGCONN)
|
|
{
|
|
using (var context = new MigrationContext(itemConn.Value))
|
|
{
|
|
entity.ISHEAD = true;
|
|
entity.ORG_ID = itemConn.Key;
|
|
try
|
|
{
|
|
context.AddEntity(entity);
|
|
context.SaveChanges();
|
|
}
|
|
catch
|
|
{
|
|
context.UpdateEntity(entity);
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
}
|