public String SaveVersion(Code _code) { var version = new CodeVersion(); version.Title = _code.Title; version.Desc = _code.Desc; version.CodeId = _code.Id; version.Content = _code.Content; version.Version = _code.Version; version.Id = Guid.NewGuid().ToString(); String versionid = Db.Insert(version); return versionid; }
/// <summary> /// 保存代码 /// </summary> /// <param name="_code"></param> /// <returns></returns> public Code SaveCode(Code _code) { if (!String.IsNullOrEmpty(_code.TreeId)) { var codeFolder = Db.Get<CodeFolder>(_code.TreeId); if (codeFolder == null) { throw new Exception("文件夹不存在!"); } } else { throw new Exception("请指定文件夹!"); } CodeVersion version = new CodeVersion(); //Guid id = Guid.Empty; String id = null; bool saveOk = false; _code.GetNewVersion(); _code.LastChangeTime = DateTime.Now; if (String.IsNullOrWhiteSpace(_code.Id)) { _code.CreateTime = DateTime.Now; _code.Id = Guid.NewGuid().ToString(); id = Db.Insert(_code); if (id!=null) { saveOk = true; } else { saveOk = false; throw new Exception("代码保存失败"); } } else { id = _code.Id; var code = Db.Get<Code>(id); if (code!=null) { saveOk = Db.Update(_code); } else { id = Db.Insert(_code); } if (false == saveOk ) { throw new Exception("代码更新失败"); } } if (String.IsNullOrWhiteSpace(_code.Id)) { throw new Exception("Can't save the Code"); } if (true == saveOk) { if (_code.Version != "1.0.0") { SaveVersion(_code); } SaveIndex(_code); } return _code; }