public async Task <IActionResult> Edit(int id, [Bind("ID,Path,Name,CreationDate")] PreAssemblyModel preAssemblyModel) { if (id != preAssemblyModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(preAssemblyModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PreAssemblyModelExists(preAssemblyModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(preAssemblyModel)); }
public async Task <IActionResult> Create(PreAssemblyViewModel modelView, List <IFormFile> assemblyFiles) { string rootFilePath = ""; if (modelView.AssemblyFiles != null) { string sldasmFile = CheckAssemblyFiles(assemblyFiles); if (sldasmFile == null) { ModelState.AddModelError("AssemblyFiles", "Assembly files should contain only 1 sldasm file"); return(View(modelView)); } var uploads = Path.Combine(_environment.WebRootPath, "uploads"); rootFilePath = Path.Combine(uploads, modelView.Name); Directory.CreateDirectory(rootFilePath); foreach (IFormFile file in assemblyFiles) { var filePath = Path.Combine(rootFilePath, file.FileName); file.CopyTo(new FileStream(filePath, FileMode.Create)); } } var model = new PreAssemblyModel { Name = modelView.Name, Path = rootFilePath, CreationDate = DateTime.Now, Assembly = null }; // to do : Return something if (ModelState.IsValid) { _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }