public async Task <IActionResult> Create([Bind("Id,VersionNumber,VersionMessage,VersionDate")] Versions versions) { if (ModelState.IsValid) { _context.Add(versions); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(versions)); }
public async Task <IActionResult> Create([Bind("Id,Heading,Templateid")] Tableofcontent tableofcontent) { if (ModelState.IsValid) { _context.Add(tableofcontent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Templateid"] = new SelectList(_context.TemplateVersion, "Id", "Name", tableofcontent.Templateid); return(View(tableofcontent)); }
public async Task <IActionResult> Create([Bind("Id,FunctionName,FunctionExample,AlternateExample,ImagePath,FunctionDescription,ExampleExaplanation,AlternateExamplesExplanation,TableOfContentHeading")] TemplateVersion templateVersion) { try { var file = Request.Form.Files[0]; var folder = Path.Combine(_environment.WebRootPath, "images/"); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var filePaths = new List <string>(); if (file.Length > 0) { var filePath = Path.GetFileName(file.FileName); filePaths.Add(filePath); string fullpath = Path.Combine(folder, filePath); string relaticePath = "~/images/" + '/' + filePath; using (var stream = new FileStream(Path.Combine(folder, filePath), FileMode.Create)) { file.CopyTo(stream); templateVersion.ImagePath = relaticePath; } } } catch (Exception e) { } finally { if (ModelState.IsValid) { if (_context.TemplateVersion.Any(x => x.FunctionName == templateVersion.FunctionName) || _context.TemplateVersion.Any(x => x.FunctionDescription == templateVersion.FunctionDescription)) { } else { _context.Add(templateVersion); await _context.SaveChangesAsync(); } } } return(RedirectToAction(nameof(Index))); // return View(templateVersion); }