public JsonResultModel <RIFileDTOModel> UploadFileByUrl(RIFileDTOModel fm) { var result = new JsonResultModel <RIFileDTOModel> { Status = JsonResponseStatus.Failed }; string docId = ""; var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket(); var backofficeUser = ""; if (auth != null) { backofficeUser = auth.Name; } fm.CreateUser = backofficeUser; RIFileModel _fileMo = Mapper.Map <RIFileModel>(fm); try { var _infoFile = _IRlFileService.CreateFileByUrl(_fileMo, out docId); _fileMo.DocID = docId; result.Data = Mapper.Map <RIFileDTOModel>(_fileMo); result.Status = JsonResponseStatus.Success; result.Code = "save url success"; } catch (Exception ex) { result.Status = JsonResponseStatus.Failed; result.Code = ex.Message; } return(result); }
public RIFileModel UpdateFile(RIFileModel cplnRI) { RIFileModel result = null; var _sql = new Sql(@"update [APlatformAppSchema].[lnRIFile] set Title=@0 ,Content=@1, UPDATETIME =GETDATE() where DocID=@2 ", new SqlParameter { DbType = DbType.String, Value = cplnRI.Title }, new SqlParameter { DbType = DbType.String, Value = cplnRI.Content }, new SqlParameter { DbType = DbType.String, Value = cplnRI.DocID }); try { var reFileDocid = lnRIFile.repo.Execute(_sql); result = cplnRI; } catch (Exception ex) { throw new RequestErrorException(string.Format("update fileInfo {0} failed", cplnRI.DocID + "__" + ex.Message)); } return(result); }
public RIFileModel CreateFileByUrl(RIFileModel cplnRI, out string docId) { if (string.IsNullOrEmpty(cplnRI.Path)) { throw new RequestErrorException("RlFile File is null"); } if (!cplnRI.Path.StartsWith("http")) { throw new RequestErrorException("Please enter the correct url and Starting with HTTP"); } else { cplnRI.MimeType = "url"; cplnRI.DocID = System.Guid.NewGuid().ToString("N"); cplnRI.FileName = ""; } if (string.IsNullOrEmpty(cplnRI.Title)) { //cplnRI.Title = ""; throw new RequestErrorException("RlFile title cannot be empty"); } if (string.IsNullOrEmpty(cplnRI.Content)) { cplnRI.Content = ""; } if (string.IsNullOrEmpty(cplnRI.DocumentID)) { throw new RequestErrorException("RlFile DocumentID is null"); } return(_iRlFileDataProvider.CreateFileInfo(cplnRI, out docId)); }
public RIFileModel UpdateFile(RIFileModel cplnRI) { if (string.IsNullOrEmpty(cplnRI.Title)) { throw new RequestErrorException("RlFile title is null"); } return(_iRlFileDataProvider.UpdateFile(cplnRI)); }
public RIFileModel GetModelStream(RIFileModel model) { using (FileStream fs = File.Open(model.Path, FileMode.Open, FileAccess.Read)) { model.Stream = new MemoryStream(); byte[] bts = new byte[fs.Length]; fs.Read(bts, 0, bts.Length); model.Stream.Write(bts, 0, bts.Length); } return(model); }
public RIFileModel GetFileBydocId(string docId) { RIFileModel _filemode = null; var _sql = new Sql("select * from [APlatformAppSchema].[lnRIFile] where DocID=@0", new SqlParameter { DbType = DbType.String, Value = docId }); try { lnRIFile _riFile = lnRIFile.SingleOrDefault(_sql); _filemode = Mapper.Map <RIFileModel>(_riFile); } catch (Exception ex) { throw new RequestErrorException(string.Format("select {0} failed", docId + "__" + ex.Message)); } return(_filemode); }
public RIFileModel CreateFileInfo(RIFileModel cplnRI, out string docId) { if (string.IsNullOrEmpty(cplnRI.Path)) { throw new RequestErrorException("RlFile File is null"); } if (string.IsNullOrEmpty(cplnRI.Title)) { throw new RequestErrorException("RlFile title cannot be empty"); } if (string.IsNullOrEmpty(cplnRI.Content)) { cplnRI.Content = ""; } if (string.IsNullOrEmpty(cplnRI.DocumentID)) { throw new RequestErrorException("RlFile DocumentID is null"); } return(_iRlFileDataProvider.CreateFileInfo(cplnRI, out docId)); }
public void DowloadInfo(RIFileModel model, string path) { model.Path = path; model = GetModelStream(model); var downLoadName = GetDownLoadFileName(model.FileName, model.Path); var filename = ""; if (HttpContext.Current.Request.Browser.Browser == "IE" || Regex.IsMatch(HttpContext.Current.Request.UserAgent, @"Trident/7.*rv:11")) { filename = HttpUtility.UrlEncode(downLoadName); } filename = ContentDispositionUtil.GetHeaderValue(downLoadName); HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); HttpContext.Current.Response.ContentType = model.MimeType; HttpContext.Current.Response.AddHeader("Content-disposition", filename); HttpContext.Current.Response.BinaryWrite(model.Stream.GetBuffer()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }
public JsonResultModel <RIFileDTOModel> ModifyFileInfo(RIFileDTOModel model) { var result = new JsonResultModel <RIFileDTOModel> { Status = JsonResponseStatus.Failed }; RIFileModel _rIFileModel = null; try { _rIFileModel = Mapper.Map <RIFileModel>(model); var _fileInfo = _IRlFileService.UpdateFile(_rIFileModel); result.Status = JsonResponseStatus.Success; result.Data = Mapper.Map <RIFileDTOModel>(_fileInfo); } catch (Exception ex) { result.Code = ex.Message; result.Status = JsonResponseStatus.Failed; } return(result); }
public RIRecordModel SaveNewVersionRecord(RIRecordModel _r1) { RIRecordModel ret = null; LnRIRecordEntityModel _r2 = null; RIRecordModel _r1new = new RIRecordModel(); //_mapperService.MapModel<RIRecordModel>(_r1);//先拷贝一份旧数据 _r1new = new RIRecordModel() { ID = _r1.ID, DocID = _r1.DocID, CheckItem = _r1.CheckItem, IsLatest = _r1.IsLatest , CheckFiles = _r1.CheckFiles, DocumentNumber = _r1.DocumentNumber, EntityID = _r1.EntityID, Author = _r1.Author, EffectiveDate = _r1.EffectiveDate , CREATETIME = _r1.CREATETIME, IsDelete = _r1.IsDelete, MetaPath = _r1.MetaPath, PackageID = _r1.PackageID, Path = _r1.Path, ReferenceDocument = _r1.ReferenceDocument, Risk = _r1.Risk, SubTopic = _r1.SubTopic , Summary = _r1.Summary, Title = _r1.Title, Topic = _r1.Topic, UPDATETIME = DateTime.Now, Version = _r1.Version }; lnRIRecord.repo.BeginTransaction(); try { int _newversion = _lnRIRecordDataProvider.GetOldVersionRecordMax(_r1) + 1; //1.先保存新的版本号 _lnRIRecordDataProvider.UpdOldVersionRecord(_mapperService.MapModel <RIRecordModel>(_r1)); //2.更新老版本的islast string _newPath = _xmlDBSavePath + "crcd" + "/" + _r1.EntityID + "_" + _newversion + ".XML"; string _newMetaPath = _xmlDBSavePath + "crcd" + "/" + _r1.EntityID + "_" + _newversion + "_META.XML"; _r1new.Version = _newversion; _r1new.DocID = this.GetMaxId().ToString(); _r1new.UPDATETIME = DateTime.Now; _r1new.CREATETIME = DateTime.Now; _r1new.Path = _newPath; _r1new.MetaPath = _newMetaPath; _r1new.IsLatest = true; _lnRIRecordDataProvider.AddRecord(_r1new); _r2 = new LnRIRecordEntityModel() { EntityID = _r1.EntityID, LatestDocID = _r1new.DocID, Title = _r1.Title, Updatetime = DateTime.Now }; _lnRIRecordDataProvider.UpdRecordEntity(_r2);//3.更新entity表 //4.更新checkitem关系表 List <RICheckItemModel> _rr1 = new List <RICheckItemModel>(); var _oldlist = _checkItemService.GetCheckItemList(_r1.DocID);//老状态的checkitem //List<RICheckItemModel> _delRefCheck = new List<RICheckItemModel>();//包括新checkitem和新版本的checkitem也就是前端传进来docid=空的,在原来的documentid里不应该存在了 //var q1 = from c in _r1.CheckItem // where string.IsNullOrEmpty(c.DocID) // select new RICheckItemModel { DocID = c.DocID, EntityID = c.EntityID }; //_delRefCheck = q1.Cast<RICheckItemModel>().ToList<RICheckItemModel>(); _rr1 = CreateCheckItem(_r1.CheckItem, _oldlist, _r1.ID); //MaintainRIRelRecordCheckItem(_rr1, _r1.ID);//5.维护原来的关系 //6.升版本后把老的documentid的维护关系中排除新的checkitemid,为了不在旧版本的doc里看到新版本的东西 //foreach (var cc in _delRefCheck) //{ // //_recordCheckItemService.DeleteRecordCheckItemById(cc.DocID, _r1.ID); //} MaintainRIRelRecordCheckItem(_rr1, _r1new.DocID);//7.新建升级后版本的关系 lnRIRecord.repo.CompleteTransaction(); try { if (_r1new.CheckFiles != null && _r1new.CheckFiles.Count > 0) { foreach (var fileDoc in _r1new.CheckFiles) { RIFileModel _newFile = new RIFileModel(); string _docid = ""; var _OldFile = _fileService.GetFileBydocId(fileDoc); _newFile = _OldFile; _newFile.DocID = System.Guid.NewGuid().ToString("N"); _newFile.DocumentID = _r1new.DocID; _newFile.CreateUser = new HttpContextWrapper(HttpContext.Current).User.Identity.Name; var retFile = _iRlFileDataProvider.CreateFileInfo(_newFile, out _docid); } //_fileService.UpdateFilesByDocumentId(_r1new.CheckFiles, _r1new.DocID); } } catch (Exception ex) { throw new RequestErrorException(ex.Message + "__db for error by save new");; } } catch (Exception ex) { LogHelper.Error <lnRIRecordService>("Save new version record Failed! \n", ex); lnRIRecord.repo.AbortTransaction(); } //生成XML ToXml(_r1new); ret = _r1new; return(ret); }
public RIRecordModel CreateRecord(RIRecordModel _model) { if (_model == null) { throw new RequestErrorException("-1001");//create record failed } if (_model.PackageID == null || _model.Topic == null || _model.SubTopic == null) { throw new RequestErrorException("-1000");//please select catagory } if (string.IsNullOrEmpty(_model.Author)) { throw new RequestErrorException("Please fill the author");//Please fill the author } if (_model.Author.Length > 50) { throw new RequestErrorException("Author is too long");//Please fill the author } if (_lnRIRecordDataProvider.ExistsRecordTitle(_model.Title)) { throw new RequestErrorException("Please use another title");//already exist title } _model.DocID = this.GetMaxId().ToString(); _model.EntityID = (Convert.ToInt64(_model.DocID) - 1).ToString(); _model.Version = 1; _model.IsLatest = true; _model.CREATETIME = DateTime.Now; _model.UPDATETIME = DateTime.Now; _model.EffectiveDate = DateTime.Now; _model.Path = _xmlDBSavePath + "crcd" + "/" + (Convert.ToInt64(_model.DocID) - 1).ToString() + "_1.XML"; _model.MetaPath = _xmlDBSavePath + "crcd" + "/" + (Convert.ToInt64(_model.DocID) - 1).ToString() + "_1_META.XML"; lnRIRecord.repo.BeginTransaction(); try { //var saveResult = _recordService.AddRecord(model); var _saveResult = AddRecord(_model, new LnRIRecordEntityModel() { EntityID = _model.EntityID, CreateTime = DateTime.Now, LatestDocID = _model.DocID, Title = _model.Title, Updatetime = DateTime.Now }); if (_saveResult == null) { throw new RequestErrorException("-1001");//create record failed } List <RICheckItemModel> _rr1 = new List <RICheckItemModel>(); if (_model.CheckItem != null && _model.CheckItem.Count > 0) { _model.CheckItem.ForEach(o => { o.ParentRecordId = _saveResult.DocID; }); _rr1 = CreateCheckItem(_model.CheckItem, new List <RICheckItemModel>() { }, _model.DocID); _model.CheckItem = _rr1; } MaintainRIRelRecordCheckItem(_rr1, _model.DocID); lnRIRecord.repo.CompleteTransaction(); try { if (_model.CheckFiles != null && _model.CheckFiles.Count > 0) { foreach (var fileDoc in _model.CheckFiles) { RIFileModel _newFile = new RIFileModel(); string _docid = ""; var _OldFile = _fileService.GetFileBydocId(fileDoc); _newFile = _OldFile; _newFile.DocID = System.Guid.NewGuid().ToString("N"); _newFile.DocumentID = _model.DocID; _newFile.CreateUser = new HttpContextWrapper(HttpContext.Current).User.Identity.Name; var retFile = _iRlFileDataProvider.CreateFileInfo(_newFile, out _docid); } //_fileService.UpdateFilesByDocumentId(_r1new.CheckFiles, _r1new.DocID); } } catch (Exception ex) { throw new RequestErrorException(ex.Message + "__db for error"); } } catch (Exception ex) { LogHelper.Error <lnRIRecordService>("CreateRecord Failed! \n", ex); lnRIRecord.repo.AbortTransaction(); throw new RequestErrorException("CreateRecord Failed! No XML generated " + ex.Message);//create record failed } var _r = _mapperService.MapModel <RIRecordModel>(_model); //生成XML ToXml(_r); return(_model); }
public RIFileModel CreateFileInfo(RIFileModel cplnRI, out string docId) { RIFileModel result = null; if (string.IsNullOrEmpty(cplnRI.FileName)) { cplnRI.FileName = ""; } if (string.IsNullOrEmpty(cplnRI.Content)) { cplnRI.Content = ""; } lnRIFile _reFile = null; var _sql = new Sql(@"INSERT INTO [APlatformAppSchema].[lnRIFile] (DocID, [Title] ,[MimeType] ,[Path] ,[CREATETIME] ,[Content] ,[DocumentID] ,[UPDATETIME] ,[FileName],[CreateUser]) output inserted.DocID VALUES (@0 ,@1 ,@2 ,@3 ,@4 ,@5 ,@6 ,@7 ,@8 ,@9)", new SqlParameter { DbType = DbType.String, Value = cplnRI.DocID }, new SqlParameter { DbType = DbType.String, Value = cplnRI.Title }, new SqlParameter { DbType = DbType.String, Value = cplnRI.MimeType }, new SqlParameter { DbType = DbType.String, Value = cplnRI.Path }, new SqlParameter { DbType = DbType.DateTime, Value = DateTime.Now }, new SqlParameter { DbType = DbType.String, Value = cplnRI.Content }, new SqlParameter { DbType = DbType.String, Value = cplnRI.DocumentID }, new SqlParameter { DbType = DbType.DateTime, Value = DateTime.Now }, new SqlParameter { DbType = DbType.String, Value = cplnRI.FileName }, new SqlParameter { DbType = DbType.String, Value = cplnRI.CreateUser } ); try { lnRIFile.repo.BeginTransaction(); _reFile = Mapper.Map <lnRIFile>(cplnRI); var reFileDocid = lnRIFile.repo.ExecuteScalar <string>(_sql); if (cplnRI.DocumentID != "-1") { var _sql2 = new Sql(@"INSERT INTO APlatformAppSchema.lnRIRelRecordTools ( DocID, FileDocID ) VALUES(@0, @1)", new SqlParameter { DbType = DbType.String, Value = cplnRI.DocumentID }, new SqlParameter { DbType = DbType.String, Value = reFileDocid }); lnRIRelRecordTool.repo.Execute(_sql2); } lnRIFile.repo.CompleteTransaction(); result = cplnRI; docId = reFileDocid; } catch (Exception ex) { lnRIFile.repo.AbortTransaction(); throw new RequestErrorException(string.Format("CreateFile {0} failed", cplnRI.DocID + "__" + ex.Message)); } return(result); }
public ActionResult UploadFile(RIFileDTOModel fm) { var result = new JsonResultModel <RIFileDTOModel> { Status = JsonResponseStatus.Failed }; var listExtension = _IRIFileContentService.GetFileExtension(); string docId = ""; var auth = HttpContext.User.Identity; var backofficeUser = ""; if (auth != null) { backofficeUser = auth.Name; } if (Request.Files["file"] != null && !string.IsNullOrEmpty(Request.Files["file"].FileName)) { var file = Request.Files["file"]; string realName = _IRlFileService.GetRealFileName(file.FileName); var fileExtension = realName.Split('.'); RIFileModel _fileModel = null; if (listExtension.Any(o => o.FileExtension.IndexOf(fileExtension[fileExtension.Length - 1], StringComparison.OrdinalIgnoreCase) >= 0)) { try { int i = file.FileName.LastIndexOf("."); string _subStr = file.FileName.Substring(i).ToLower(); string _cotType = ""; foreach (var item in listExtension) { if (item.FileExtension.Contains("|")) { var _filExt = item.FileExtension.Split('|'); for (int j = 0; j < _filExt.Length; j++) { if (_filExt[j].Equals(_subStr)) { _cotType = item.Content.ToLower(); } } } else if (item.FileExtension.Equals(_subStr)) { _cotType = item.Content.ToLower(); } } string severFileName = _IRlFileService.GetDirsAndFileName(file.FileName, fm.DocumentID, "Aplatform.CMSContentDircs"); RIFileDTOModel model = new RIFileDTOModel(); model.DocID = System.Guid.NewGuid().ToString("N"); model.Title = fm.Title; model.Content = fm.Content; model.MimeType = "application/" + _cotType; model.Path = severFileName; model.FileName = realName; model.DocumentID = fm.DocumentID; model.CreateUser = backofficeUser; _fileModel = Mapper.Map <RIFileModel>(model); var _createFile = _IRlFileService.CreateFileInfo(_fileModel, out docId); var path = this._IRlFileService.GetDownLoadUrl(_createFile.Path, _createFile.DocumentID); file.SaveAs(path); result.Data = Mapper.Map <RIFileDTOModel>(_createFile); result.Status = JsonResponseStatus.Success; result.Code = "upload file success"; } catch (Exception ex) { _IRlFileService.DeleteFileById(docId); result.Status = JsonResponseStatus.Failed; result.Code = ex.Message; } } } return(new JsonResult <JsonResultModel <RIFileDTOModel> >(result)); }