public void Delete(Guid Guid) { sysBpmsDocument document = this.Context.sysBpmsDocuments.FirstOrDefault(d => d.GUID == Guid); if (document != null) { this.Context.sysBpmsDocuments.Remove(document); } }
public ResultOperation Update(sysBpmsDocument document) { ResultOperation resultOperation = new ResultOperation(); if (resultOperation.IsSuccess) { this.UnitOfWork.Repository <IDocumentRepository>().Update(document); this.UnitOfWork.Save(); } return(resultOperation); }
public ResultOperation InActive(Guid Guid) { ResultOperation resultOperation = new ResultOperation(); if (resultOperation.IsSuccess) { sysBpmsDocument document = this.GetInfo(Guid); document.IsDeleted = true; this.UnitOfWork.Repository <IDocumentRepository>().Update(document); this.UnitOfWork.Save(); } return(resultOperation); }
protected void Download(sysBpmsDocument Document) { if (Document != null) { string fileType = Document.FileExtention; string contentType = ""; switch (fileType.ToLower().TrimStart('.')) { case "jpg": contentType = "image/jpeg"; break; case "png": contentType = "image/png"; break; case "gif": contentType = "image/gif"; break; case "doc": contentType = "application/msword"; break; case "docx": contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case "zip": contentType = "application/zip"; break; case "pdf": contentType = "application/pdf"; break; case "rar": contentType = "application/zip"; break; case "wav": contentType = "audio/wav"; break; case "wave": contentType = "audio/wav"; break; case "wax": contentType = "audio/x-ms-wax"; break; case "wma": contentType = "audio/mid"; break; case "mid": contentType = "audio/x-ms-wax"; break; case "midi": contentType = "audio/mid"; break; case "mp3": contentType = "audio/mpeg"; break; case "3gp": contentType = "video/3gpp"; break; case "avi": contentType = "video/x-msvideo"; break; case "flv": contentType = "video/x-flv"; break; case "mov": contentType = "video/quicktime"; break; case "movie": contentType = "video/x-sgi-movie"; break; case "mp4": contentType = "video/mp4"; break; case "mpe": contentType = "video/mpeg"; break; case "mpeg": contentType = "video/mpeg"; break; case "wmv": contentType = "video/x-ms-wmv"; break; case "tiff": contentType = "image/tiff"; break; case "bmp": contentType = "image/bmp"; break; default: contentType = "application/octet-stream"; break; } Document.CaptionOf = string.IsNullOrWhiteSpace(Document.CaptionOf) ? "File" : Document.CaptionOf; if (System.IO.File.Exists(BPMSResources.FilesRoot + Document.GUID)) { using (FileStream fsSource = new FileStream(BPMSResources.FilesRoot + Document.GUID, FileMode.Open, FileAccess.Read)) { HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + Document.CaptionOf + "." + fileType); HttpContext.Current.Response.ContentType = contentType; int length = 1024 * 10000; int index = 0; byte[] fileBytes = new byte[length]; while ((index = fsSource.Read(fileBytes, 0, length)) > 0) { HttpContext.Current.Response.OutputStream.Write(fileBytes, 0, index); } HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } } } }
public void Update(sysBpmsDocument document) { this.Context.Entry(document).State = EntityState.Modified; }
public void Add(sysBpmsDocument document) { this.Context.sysBpmsDocuments.Add(document); }
public ResultOperation SaveFile(System.IO.Stream inputStream, string fileName, Guid?entityID, Guid?entityDefID, Guid documentDefID, string captionOF, bool replace) { ResultOperation resultOperation = new ResultOperation(); if (inputStream == null || inputStream.Length <= 0) { return(resultOperation); } sysBpmsDocument PostDocument = null; sysBpmsDocumentDef documentDef = new DocumentDefService(base.UnitOfWork).GetInfo(documentDefID); try { Guid Guid = System.Guid.NewGuid(); string fe = System.IO.Path.GetExtension(fileName).Trim('.').ToLower(); if (!string.IsNullOrWhiteSpace(documentDef.ValidExtentions) && !documentDef.ValidExtentions.ToStringObj().Trim().ToLower().Split(',').Any(c => c.Trim('.') == fe)) { resultOperation.AddError(string.Format(LangUtility.Get("FileNotValid.Text", "Engine"), documentDef.DisplayName)); return(resultOperation); } if (documentDef.MaxSize > 0 && documentDef.MaxSize * 1024 < inputStream.Length) { resultOperation.AddError(string.Format(LangUtility.Get("FileSizeError.Text", "Engine"), documentDef.DisplayName)); return(resultOperation); } if (!System.IO.Directory.Exists(BPMSResources.FilesRoot.Trim('\\'))) { System.IO.DirectoryInfo DirectoryInfoObject = System.IO.Directory.CreateDirectory(BPMSResources.FilesRoot.Trim('\\')); } using (System.IO.FileStream saveStream = System.IO.File.Create(BPMSResources.FilesRoot.Trim('\\') + "\\" + Guid)) { byte[] bytes = new byte[1024]; int lenght = 0; while ((lenght = inputStream.Read(bytes, 0, bytes.Length)) > 0) { saveStream.Write(bytes, 0, lenght); } } PostDocument = new sysBpmsDocument() { IsDeleted = false, AtachDateOf = DateTime.Now, CaptionOf = string.IsNullOrWhiteSpace(captionOF) ? documentDef.DisplayName : captionOF, EntityID = entityID, EntityDefID = entityDefID, DocumentDefID = documentDefID, FileExtention = fe, GUID = Guid, ThreadID = base.EngineSharedModel.CurrentThreadID, }; if (replace) { var _Document = this.DocumentService.GetList(documentDefID, entityDefID, entityID, "", false, null, null).FirstOrDefault(); if (_Document != null) { _Document.IsDeleted = true; this.DocumentService.Update(_Document); } } this.DocumentService.Add(PostDocument); } catch { resultOperation.AddError(LangUtility.Get("FileSaveError.Text", "Engine")); } resultOperation.CurrentObject = PostDocument; return(resultOperation); }