/// <summary> /// 添加或修改 /// </summary> /// <param name="model"></param> public void AddOrModity(Corporation model) { try { this.corpRepository.UnitOfWork.BeginTrans(); model.ParentId = (string.IsNullOrEmpty(model.ParentId) ? Guid.Empty.ToString() : model.ParentId); model.OldParentId = (string.IsNullOrEmpty(model.OldParentId) ? Guid.Empty.ToString() : model.OldParentId); model.PyCode = model.CorpName.ToConvertPyCode(); if (!string.IsNullOrEmpty(model.Id)) { model.LastUpdateDate = DateTime.Now; if (model.ParentId != model.OldParentId) { var oldAutomaticCode = ""; oldAutomaticCode = model.AutomaticCode; model.AutomaticCode = this.corpRepository.GetAutomaticCode(model.ParentId); this.corpRepository.SetAutomaticCode(oldAutomaticCode, model.AutomaticCode, model.Id); } this.corpRepository.Modity(model); } else { model.GenerateNewIdentity(); model.CreateDate = DateTime.Now; model.LastUpdateDate = DateTime.Now; model.AutomaticCode = this.corpRepository.GetAutomaticCode(model.ParentId); model.ParentCorp = null; this.corpRepository.Add(model); } this.corpRepository.SaveChanges(); this.corpRepository.UnitOfWork.Commit(); } catch (Exception ex) { this.corpRepository.UnitOfWork.Rollback(); throw ex; } }