using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.FM;
using APT.BaseData.Services.DomainServices;
using APT.BaseData.Services.Services.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.HM;

using APT.MS.Domain.Entities.SC;
using APT.MS.Domain.Entities.SC.SC;
using APT.MS.Domain.Enums;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace APT.SC.WebApi.Controllers.Api.SC
{
    [Route("api/SC/SCDocumentLibrary")]
    public class SCDocumentController : AuthorizeApiController<T_SC_DOCUMENT_LIBRARY>
    {
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_SC_DOCUMENT_LIBRARY entity)
        {
            return SafeExecute(() =>
            {
                var Nav_Details = entity.Nav_Details;
                List<T_SC_DOCUMENT_LIBRARY_DETAIL_FILE> Files = new List<T_SC_DOCUMENT_LIBRARY_DETAIL_FILE>();
                Nav_Details.ForEach(t =>
                {
                    if (t.Nav_Files != null && t.Nav_Files.Count() > 0)
                    {
                        Files.AddRange(t.Nav_Files);
                        t.Nav_Files = null;
                    }
                });
                UnifiedCommit(() =>
                {
                    UpdateEntityNoCommit(entity);
                    if (Nav_Details != null && Nav_Details.Any())
                        BantchSaveEntityNoCommit(Nav_Details);
                    if (Files != null && Files.Any())
                        BantchSaveEntityNoCommit(Files);
                });
                return true;
            });
        }
    }
}
