public async Task <IActionResult> OnPostAsync(int id) { PrintModel model = await buildModel(id); if (model != null) { if (!model.IsValid()) { return(BadRequest()); } model.Amount = printAmount; model.PricePerPart = ParsePrice(pricePerPart); model.PriceTotal = ParsePrice(priceTotal); model.Snapshot = snapshot; _context.Attach(model).State = EntityState.Modified; List <PrintModelPostProcess> ppRels = await _context.PrintModelPostProcesses.Where(pmpp => pmpp.PrintModelID == id).ToListAsync(); _context.PrintModelPostProcesses.RemoveRange(ppRels); foreach (int ppid in postProcess) { PostProcess p = await _context.PostProcesses.FirstOrDefaultAsync(pp => pp.ID == ppid); if (p != null) { PrintModelPostProcess ppRel = new PrintModelPostProcess(); ppRel.PostProcess = p; ppRel.PrintModel = model; _context.PrintModelPostProcesses.Add(ppRel); } } try { await _context.SaveChangesAsync(); return(RedirectToPage("Edit", new { area = "Quotations", id = model.Quotation.ID })); } catch (Exception ex) { throw ex; } } return(BadRequest()); }
public async Task <IActionResult> OnPostExcel(int id) { PrintModel model = await buildModel(id); PrinterLayerThickness plt = null; List <PostProcess> postProcesses = await ParsePostProcesses(postProcess); if (model != null && model.Printer != null && model.LayerThickness != null) { plt = await _context.PrinterLayerThicknesses.FirstOrDefaultAsync(p => p.PrinterID == model.Printer.ID && p.LayerThicknessID == model.LayerThickness.ID); } if (model != null && plt != null) { if (!model.IsValid()) { return(BadRequest()); } if (aabb.Length > 0) { Dimensions dim = ParseAABB(aabb); model.X = dim.X; model.Y = dim.Z; // xeogl and system represent 3D space with Y as height axis, while system is required to represent height axis as Z. model.Z = dim.Y; } _calculator.SetExcelFile(model.Quotation.EngineFile); IWorkbook workbook = _calculator.GenerateWorkbook(model, plt, postProcesses, printAmount); Stream stream = new MemoryStream(); workbook.SaveToStream(stream, FileFormat.OpenXMLWorkbook); workbook.SaveAs("debug.xlsx", FileFormat.OpenXMLWorkbook); stream.Position = 0; return(File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", model.Name)); } return(BadRequest()); }
public async Task <IActionResult> OnPostPriceAsync(int id) { PrintModel model = await buildModel(id); PrinterLayerThickness plt = null; List <PostProcess> postProcesses = await ParsePostProcesses(postProcess); if (model != null && model.Printer != null && model.LayerThickness != null) { plt = await _context.PrinterLayerThicknesses.FirstOrDefaultAsync(p => p.PrinterID == model.Printer.ID && p.LayerThicknessID == model.LayerThickness.ID); } if (model != null && plt != null) { if (!model.IsValid()) { return(BadRequest()); } if (aabb.Length > 0) { Dimensions dim = ParseAABB(aabb); model.X = dim.X; model.Y = dim.Z; // xeogl and system represent 3D space with Y as height axis, while system is required to represent height axis as Z. model.Z = dim.Y; } Dictionary <int, double> postProcessPrices; _calculator.SetExcelFile(model.Quotation.EngineFile); double price = _calculator.GetPrice(model, plt, postProcesses, printAmount, out postProcessPrices); return(new JsonResult(new { Price = price, PostProcesses = postProcessPrices })); } return(BadRequest()); }