using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
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;
using System.Linq.Expressions;

namespace APT.SC.WebApi.Controllers.Api.WB
{
    [Route("api/WB/WBCheckAreaEnum")]
    public class WBCheckAreaEnumController : AuthorizeApiController<T_WB_CHECK_AREA_ENUM>
    {
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_WB_CHECK_AREA_ENUM entity)
        {
            return SafeExecute(() =>
            {
                var check = GetEntity<T_WB_CHECK_AREA_ENUM>(e => !e.IS_DELETED && e.NAME == entity.NAME && e.ID != entity.ID);
                if (check != null)
                {
                    throw new Exception("区域名称不能重复！");
                }
                entity.AREA = entity.NAME;
                UpdateEntity(entity);
                return true;
            });
        }
    }
}
