public JsonResult GetPartLayouts(Guid partId) { var model = new PartViewModel(); var projectPart = _projectPartRepository.GetProjectPart(partId); if (projectPart != null) { var layouts = _projectPartRepository.GetProjectPartLayouts(partId); model.Layouts = new List <LayoutViewModel>(); foreach (var layout in layouts) { LayoutViewModel layoutModel = new ProjectPartLayoutConverter().ConvertToView(layout); model.Layouts.Add(layoutModel); } } else { var layouts = _partRepository.GetPartLayouts(partId); model.Layouts = new List <LayoutViewModel>(); foreach (var layout in layouts) { var layoutModel = new PartLayoutConverter().ConvertToView(layout); model.Layouts.Add(layoutModel); } } return(Json(model, JsonRequestBehavior.AllowGet)); }
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)); }
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)); }