using APT.BaseData.Domain.Entities;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.HM;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;

namespace APT.HM.WebApi.Controllers.Api
{
    [Route("api/HM/HMOperationTaskDistinguish")]
    public partial class OperationTaskDistinguishAnalyzeController : AuthorizeApiController<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>
    {
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_HM_OPERATION_TASK_DISTINGUISH entity)
        {
            return SafeExecute<bool>(() =>
            {
                var users = entity.Nav_Users;
                var distinguishdetails = entity.Nav_DistinguishDetails;
                entity.Nav_Users = null;
                entity.Nav_DistinguishDetails = null;
                this.UnifiedCommit(() =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);   //保存主表
                    if (users != null && users.Any())
                        BantchSaveEntityNoCommit(users);    //保存子表
                    if (distinguishdetails != null && distinguishdetails.Any())
                        BantchSaveEntityNoCommit(distinguishdetails);    //保存子表
                });
                return true;
            });
        }
    }
}
