using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.FO;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.LR;
using APT.MS.Domain.Entities.WB;
using APT.MS.Domain.Enums;
using APT.Utility;
using Castle.Core.Internal;
using InfluxData.Net.InfluxDb.Models.Responses;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.Differencing;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;

namespace APT.SC.WebApi.Controllers.Api.WB
{
    /// <summary>
    /// 工种
    /// </summary>
    [Route("api/WB/WBWorktype")]
    public class WBWorktypeController : AuthorizeApiController<T_WB_WORKTYPE>
    {
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_WB_WORKTYPE entity)
        {
            return SafeExecute(() =>
            {
                var check = GetEntity<T_WB_WORKTYPE>(e => e.ID != entity.ID && e.NAME == entity.NAME);
                if (check != null)
                {
                    throw new Exception("系统已存在该工种！");
                }
                else
                {
                    UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);
                    });
                    return true;
                }

            });
        }
    }
}
