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.Infrastructure.Api; using APT.Migrations; using APT.BaseData.Domain.Entities.OP; using APT.BaseData.Domain.Enums.OP; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices.OP; using Microsoft.Data.SqlClient; namespace APT.PF.WebApiControllers.Api.PF { /// /// /// [Route("api/PF/PFBititle")] public class PFBititleController : AuthorizeApiController { IOPTenantDBConnService OPTenantDBConnService { get; set; } /// /// /// /// public PFBititleController(IOPTenantDBConnService opTenantDBConnService) { OPTenantDBConnService = opTenantDBConnService; } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_PF_BITITLE entity) { return SafeExecute(() => { T_PF_BITITLE check = null; T_PF_BITITLE ModelUpdateOld = null; if (entity.VERSION == 0) { entity.VERSION = 1; } if (string.IsNullOrEmpty(entity.TITLE) || entity.TITLE == "

") { throw new Exception("请输入标语后再操作!"); } if (entity.STATUS == STATEEnum.release) { check = GetEntity(e => e.STATUS == STATEEnum.release); if (check != null) { if (check.ID == entity.ID) { //旧数据 撤回状态 本条修改ID 父项ID 版本号等 ModelUpdateOld = check; ModelUpdateOld.STATUS = STATEEnum.Draft; entity.ID = Guid.NewGuid(); entity.PARENTID = ModelUpdateOld.ID; entity.VERSION = ModelUpdateOld.VERSION + 1; entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value; } else { throw new Exception("只能有一条已发布的标语!如需发布本本条,请撤回已发布的标语!"); } } } else if (entity.STATUS == STATEEnum.Delete) { entity.IS_DELETED = true; } else if (entity.STATUS == STATEEnum.Draft) { check = GetEntity(entity.ID); if (check != null) { if (check.STATUS == STATEEnum.release) { throw new Exception("请先撤回后再修改!"); } else if (check.TITLE != entity.TITLE) { ModelUpdateOld = check; ModelUpdateOld.STATUS = STATEEnum.Draft; entity.ID = Guid.NewGuid(); //entity.VERSION = ModelUpdateOld.VERSION + 1; //只是保存 不加版本号 entity.PARENTID = ModelUpdateOld.ID; entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value; } } } if (entity.USER_ID_CREATER == Guid.Empty) { entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value; } entity.MODIFY_TIME = DateTime.Now; if (ModelUpdateOld != null) ModelUpdateOld.MODIFY_TIME = DateTime.Now; this.UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (ModelUpdateOld != null) { UpdateEntityNoCommit(ModelUpdateOld); } }); return true; }); } } }