public FileStreamResult GetLayout(Guid layoutId, bool isProject) { var layout = new LayoutPdf(); if (isProject) { var dbLayout = _projectPartRepository.GetProjectPartLayout(layoutId); layout = new ProjectPartLayoutConverter().ConvertToPdf(dbLayout); } else { var dbLayout = _partRepository.GetPartLayout(layoutId); layout = new PartLayoutConverter().ConvertToPdf(dbLayout); } MemoryStream ms = new MemoryStream(layout.Content, 0, 0, true, true); Response.ContentType = layout.Type; Response.AddHeader("content-disposition", "inline;filename=" + layout.Description); Response.Buffer = true; Response.Clear(); Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length); Response.OutputStream.Flush(); Response.End(); string mineType = "application/pdf"; return(new FileStreamResult(Response.OutputStream, mineType)); }
/// <summary> /// convert part layout to pdf /// </summary> /// <param name="layout"></param> /// <returns></returns> public LayoutPdf ConvertToPdf(PartLayout layout) { LayoutPdf model = new LayoutPdf(); model.Content = layout.Content; model.Type = layout.Type; model.Description = layout.Description; return(model); }
public JsonResult GetLayoutImageData(HttpPostedFileBase layout) { var model = new LayoutPdf(); if (layout == null && layout.ContentLength < 1) { model.Success = false; model.Message = "Error occurred...image file not found or contains no data."; } else { if (!layout.FileName.EndsWith(".png") && !layout.FileName.EndsWith(".jpg") && !layout.FileName.EndsWith(".pdf")) { model.Success = false; model.Message = "Error occurred...image file not in correct format."; } else { string trimmedFileName = string.Empty; byte[] tempFile = new byte[layout.ContentLength]; layout.InputStream.Read(tempFile, 0, layout.ContentLength); if (layout.FileName.EndsWith("png")) { trimmedFileName = layout.FileName.Replace(".png", ""); } else if (layout.FileName.EndsWith("jpg")) { trimmedFileName = layout.FileName.Replace(".jpg", ""); } else if (layout.FileName.EndsWith("pdf")) { trimmedFileName = layout.FileName.Replace(".pdf", ""); } model.Success = true; model.Description = trimmedFileName; } } return(Json(model, JsonRequestBehavior.AllowGet)); }
public JsonResult AddLayout(HttpPostedFileBase layout, Guid partId) { var operationResult = new OperationResult(); var model = new LayoutPdf(); if (layout != null && layout.ContentLength > 0) { byte[] tempFile = new byte[layout.ContentLength]; layout.InputStream.Read(tempFile, 0, layout.ContentLength); var currentPart = _projectPartRepository.GetProjectPart(partId); if (currentPart != null) { var newPartLayout = new ProjectPartLayoutConverter().ConvertToDomain(layout); newPartLayout.ProjectPartId = partId; newPartLayout.IsLatest = true; newPartLayout.IsMachined = currentPart.IsMachined; newPartLayout.IsRaw = currentPart.IsRaw; operationResult = _projectPartRepository.SaveProjectPartLayout(newPartLayout); if (operationResult.Success) { var partLayouts = _projectPartRepository.GetProjectPartLayouts(partId); foreach (var partLayout in partLayouts) { partLayout.IsLatest = false; _projectPartRepository.UpdateProjectPartLayout(partLayout); } model.Success = true; model.LayoutId = operationResult.ReferenceId; model.Description = operationResult.Description; model.IsProject = true; } else { model.Success = false; model.Message = operationResult.Message; } } else { var newPartLayout = new PartLayoutConverter().ConvertToDomain(layout); newPartLayout.PartId = partId; newPartLayout.IsLatest = true; newPartLayout.IsMachined = false; newPartLayout.IsRaw = false; operationResult = _partRepository.SavePartLayout(newPartLayout); if (operationResult.Success) { var partLayouts = _partRepository.GetPartLayouts(partId); foreach (var partLayout in partLayouts) { partLayout.IsLatest = false; _partRepository.UpdatePartLayout(partLayout); } model.Success = true; model.LayoutId = operationResult.ReferenceId; model.Description = operationResult.Description; model.IsProject = true; } else { model.Success = false; model.Message = operationResult.Message; } } } return(Json(model, JsonRequestBehavior.AllowGet)); }