public async Task <IActionResult> Create([Bind("Id,Name")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(course)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,CourseId")] Student student, IFormFile PhotoLocation) { if (ModelState.IsValid) { if (PhotoLocation != null) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", "UploadFiles", PhotoLocation.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await PhotoLocation.CopyToAsync(stream); } student.PhotoLocation = Path.Combine("\\", "UploadFiles", PhotoLocation.FileName); ViewData["PhotoLocation"] = "/" + Path.GetFileName(PhotoLocation.FileName); } _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }