public async Task <IActionResult> Create([Bind("MachiningToolId,ToolType,ToolDiameter,RadialMetric,Units,ToolDescription,VendorDescription,InitToolCount,ToolCount,PurchaseOrderNum,PurchaseOrderDate,PurchaseOrderCost,InvoiceNumber,VendorId,ToolingImageFile,ToolingImageBytes")] MachiningTool machiningTool)
        {
            if (ModelState.IsValid)
            {
                machiningTool.MachiningToolId = Guid.NewGuid();
                // default tool count to the initial tool count
                machiningTool.ToolCount = machiningTool.InitToolCount;
                if (machiningTool.ToolingImageFile != null)
                {
                    machiningTool.ToolingImageBytes = await FileURL.GetFileBytes(machiningTool.ToolingImageFile);
                }
                SetUIDs();
                await _repo.AddMachiningTool(machiningTool);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VendorId"] = new SelectList(await _repo.GetAllVendors(), "VendorId", "VendorName", machiningTool.VendorId);
            return(View(machiningTool));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("MachiningToolId,ToolType,ToolDiameter,RadialMetric,Units,ToolDescription,VendorDescription,InitToolCount,ToolCount,PurchaseOrderNum,PurchaseOrderDate,PurchaseOrderCost,InvoiceNumber,VendorId,ToolingImageFile,ClearToolingImage,ToolingImageBytes")] MachiningTool machiningTool)
        {
            if (id != machiningTool.MachiningToolId)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (machiningTool.ToolingImageFile != null)
                    {
                        machiningTool.ToolingImageBytes = await FileURL.GetFileBytes(machiningTool.ToolingImageFile);
                    }
                    else if (machiningTool.ClearToolingImage)
                    {
                        machiningTool.ToolingImageBytes = null;
                    }



                    SetUIDs();
                    await _repo.UpdateMachiningTool(machiningTool);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!(await MachiningToolExists(machiningTool.MachiningToolId)))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VendorId"] = new SelectList(await _repo.GetAllVendors(), "VendorId", "VendorName", machiningTool.VendorId);
            return(View(machiningTool));
        }