using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.SC.PR;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace APT.SC.WebApi.Controllers.Api.PRController
{
    /// <summary>
    ///  事项参数配置表
    /// </summary>
    [Route("api/PR/PRPostFormLinkXk")]
    public partial class PostFormLinkXkController : AuthorizeApiController<T_PR_POST_FORM_LINK_XK>
    {
        /// <summary>
        /// 新增编辑
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_PR_POST_FORM_LINK_XK entity)
        {
            return SafeExecute<bool>(() =>
            {
                var details = entity.Nav_Params;
                entity.Nav_Params = null;
                if (details != null && details.Any())
                {
                    details.ForEach(t =>
                    {
                        t.ORG_ID = entity.ORG_ID;
                        t.POST_POST_ID = entity.ID;
                    });
                }
                this.UnifiedCommit(() =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);   //保存主表
                    if (details != null && details.Any())
                        BantchSaveEntityNoCommit(details);    //保存子表
                });
                return true;
            });
        }
    }
}
