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 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 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)); }