Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        /// <summary>
        /// convert project part drawing to pdf
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public DrawingPdf ConvertToPdf(ProjectPartDrawing drawing)
        {
            DrawingPdf model = new DrawingPdf();

            model.Content        = drawing.Content;
            model.Type           = drawing.Type;
            model.RevisionNumber = drawing.RevisionNumber;

            return(model);
        }
Esempio n. 3
0
        public JsonResult GetDrawingImageData(HttpPostedFileBase drawing)
        {
            var model = new DrawingPdf();

            if (drawing == null || drawing.ContentLength < 1)
            {
                model.Success = false;
                model.Message = "Error occurred...image file not found or contains no data.";
            }
            else
            {
                if (!drawing.FileName.EndsWith(".png") && !drawing.FileName.EndsWith(".jpg") && !drawing.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[drawing.ContentLength];
                    drawing.InputStream.Read(tempFile, 0, drawing.ContentLength);

                    if (drawing.FileName.EndsWith("png"))
                    {
                        trimmedFileName = drawing.FileName.Replace(".png", "");
                    }
                    else if (drawing.FileName.EndsWith("jpg"))
                    {
                        trimmedFileName = drawing.FileName.Replace(".jpg", "");
                    }
                    else if (drawing.FileName.EndsWith("pdf"))
                    {
                        trimmedFileName = drawing.FileName.Replace(".pdf", "");
                    }

                    model.Success        = true;
                    model.RevisionNumber = trimmedFileName;
                }
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        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));
        }