using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.IServices;
using APT.Infrastructure.Core;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using APT.Utility;
using APT.Utility;
using APT.BaseData.Domain.Entities.T4;
using System.Threading.Tasks;

namespace APT.PF.WebApiControllers.Api.PF
{
    [Route("api/PF/AppVersion")]
    public class AppVersionController : AuthorizeApiController<T_PF_APP_VERSION>
    {

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("DeleteRelation")]
        public JsonActionResult<bool> DeleteRelation(string id)
        {
            return SafeExecute<bool>(() =>
            {
                var versionID = Guid.Parse(id);
                this.UnifiedCommit(() =>
                {
                    this.DeleteEntityNoCommit<T_PF_APP_VERSION_FILE>(i => i.APP_VERSION_ID == versionID);
                    this.DeleteEntityNoCommit<T_PF_APP_VERSION>(i => i.ID == versionID);
                });
                return true;
            });
        }
        /// <summary>
        /// 更新或新增数据
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_PF_APP_VERSION entity)
        {
            return SafeExecute(() =>
            {

                var detail = entity.Nav_Files;
                entity.Nav_Files = null;
                UnifiedCommit(() =>
                {
                    this.UpdateEntityNoCommit(entity);
                    if (detail != null)
                    {
                        this.BantchSaveEntityNoCommit(detail);
                    }
                });
                return true;
            });
            return WitUpdate(entity);
        }



    }
}
