using APT.BaseData.Domain.Entities.FM;
using APT.Infrastructure.Core;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace APT.FM.WebApi.Controllers.Api
{
    /// <summary>
    ///  参数设置表
    /// </summary>
    [Route("api/FM/FMParamSet")]
    public partial class ParamSetController : AuthorizeApiController<T_FM_PARAM_SET>
    {
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_FM_PARAM_SET entity)
        {
            return SafeExecute<bool>(() =>
            {
                var departments = entity.Nav_Departments;
                entity.Nav_Departments = null;
                this.UnifiedCommit(() =>
                {
                    this.UpdateEntityNoCommit(entity);
                    if (departments != null && departments.Any())
                        this.BantchSaveEntityNoCommit(departments);
                });

                return true;
            });
        }
    }
}
