public async Task <IActionResult> Edit(int id, [Bind("YogaId,YogaName,YogaStep,YdfkId")] YogaTable yogaTable) { if (id != yogaTable.YogaId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(yogaTable); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!YogaTableExists(yogaTable.YogaId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["YdfkId"] = new SelectList(_context.DiseaseTable, "DiseaseId", "DiseaseId", yogaTable.YdfkId); return(View(yogaTable)); }
public async Task <IActionResult> Create([Bind("YogaId,YogaName,YogaStep,YdfkId")] YogaTable yogaTable) { if (ModelState.IsValid) { _context.Add(yogaTable); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["YdfkId"] = new SelectList(_context.DiseaseTable, "DiseaseId", "DiseaseId", yogaTable.YdfkId); return(View(yogaTable)); }
public async Task <IActionResult> Create(ViewFile model) { if (ModelState.IsValid) { string uniqueFilename = null; if (model.formFile != null) { string ext = System.IO.Path.GetExtension(model.formFile.FileName); if (ext == ".pdf") { string upload = System.IO.Path.Combine(_env.WebRootPath, "images"); uniqueFilename = Guid.NewGuid().ToString() + "_" + model.formFile.FileName; string filepath = System.IO.Path.Combine(upload, uniqueFilename); model.formFile.CopyTo(new System.IO.FileStream(filepath, System.IO.FileMode.Create)); //string filepath = $"{_env.WebRootPath}/images/{model.formFile.FileName}"; //var stream = System.IO.File.Create(filepath); //model.formFile.CopyTo(stream); } else { TempData["Error"] = "Only Pdf files are allowed"; return(RedirectToAction("Create", "YogaTables")); } } YogaTable newfile = new YogaTable { YogaId = model.YogaId, YogaName = model.YogaName, YogaStep = uniqueFilename, Ydfk = model.Ydfk, YdfkId = model.YdfkId, }; _context.Add(newfile); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }