public FileStreamResult GetDrawing(Guid drawingId, bool isProject) { var drawing = new DrawingPdf(); if (isProject) { var projectDrawing = _projectPartRepository.GetProjectPartDrawing(drawingId); drawing = new ProjectPartDrawingConverter().ConvertToPdf(projectDrawing); } else { var partDrawing = _partRepository.GetPartDrawing(drawingId); drawing = new PartDrawingConverter().ConvertToPdf(partDrawing); } MemoryStream ms = new MemoryStream(drawing.Content, 0, 0, true, true); Response.ContentType = drawing.Type; Response.AddHeader("content-disposition", "inline;filename=" + drawing.RevisionNumber); 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)); }
public JsonResult AddDrawing(HttpPostedFileBase drawing, Guid partId) { var operationResult = new OperationResult(); var model = new DrawingPdf(); if (drawing != null && drawing.ContentLength > 0) { byte[] tempFile = new byte[drawing.ContentLength]; drawing.InputStream.Read(tempFile, 0, drawing.ContentLength); var currentPart = _projectPartRepository.GetProjectPart(partId); if (currentPart != null) { var partDrawings = _projectPartRepository.GetProjectPartDrawings(partId); foreach (var partDrawing in partDrawings) { partDrawing.IsLatest = false; _projectPartRepository.UpdateProjectPartDrawing(partDrawing); } var newPartDrawing = new ProjectPartDrawingConverter().ConvertToDomain(drawing); newPartDrawing.ProjectPartId = partId; newPartDrawing.IsLatest = true; newPartDrawing.IsMachined = currentPart.IsMachined; newPartDrawing.IsRaw = currentPart.IsRaw; operationResult = _projectPartRepository.SaveProjectPartDrawing(newPartDrawing); model.Success = true; model.DrawingId = operationResult.ReferenceId; model.RevisionNumber = operationResult.Number; model.IsProject = true; } else { var newPartDrawing = new PartDrawingConverter().ConvertToDomain(drawing); newPartDrawing.PartId = partId; newPartDrawing.IsLatest = true; newPartDrawing.IsMachined = false; newPartDrawing.IsRaw = false; operationResult = _partRepository.SavePartDrawing(newPartDrawing); if (operationResult.Success) { var partDrawings = _partRepository.GetPartDrawings(partId); foreach (var partDrawing in partDrawings) { partDrawing.IsLatest = false; _partRepository.UpdatePartDrawing(partDrawing); } model.Success = true; model.DrawingId = operationResult.ReferenceId; model.RevisionNumber = operationResult.Number; model.IsProject = true; } else { model.Success = false; model.Message = operationResult.Message; } } } else { model.Success = false; model.Message = "Unable to add drawing."; } return(Json(model, JsonRequestBehavior.AllowGet)); }