public async Task <IActionResult> Edit(int id, [Bind("Id,Cname,PictureName,Type,Date")] TablePhoto tablePhoto) { if (id != tablePhoto.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tablePhoto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TablePhotoExists(tablePhoto.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tablePhoto)); }
public async Task <IActionResult> Create([Bind("Id,Cname,PictureName,PhotoName,Date")] TablePhoto tablePhoto) { if (ModelState.IsValid) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(tablePhoto.PhotoName.FileName); string extensioName = Path.GetExtension(tablePhoto.PhotoName.FileName); tablePhoto.PictureName = fileName = fileName + extensioName; string path = Path.Combine(wwwRootPath + "/Photo/", fileName); tablePhoto.Cname = @User.Identity.Name; using (var fileStream = new FileStream(path, FileMode.Create)) { await tablePhoto.PhotoName.CopyToAsync(fileStream); } _context.Add(tablePhoto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tablePhoto)); }