using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.FO;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace APT.FO.WebApi.Controllers
{
    /// <summary>
    ///  工作票排班模板
    /// </summary>
    [Route("api/FO/FOSchedulingTemplate")]
    public partial class SchedulingTemplateController : AuthorizeApiController<T_FO_SCHEDULING_TEMPLATE>
    {
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_FO_SCHEDULING_TEMPLATE entity)
        {
            return SafeExecute<bool>(() =>
            {
                var details = entity.Nav_Details;
                entity.Nav_Details = null;
                this.UnifiedCommit(() =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);
                    if (details != null && details.Any())
                        BantchSaveEntityNoCommit(details);
                });
                return true;
            });
        }
    }
}
