public async Task <IActionResult> BeatArt(int id, BeatArtFilePathViewModel beatArt) { if (id != beatArt.ID) { return(NotFound()); } Beat beatUpdate = _context.Beat.Find(beatArt.ID); if (beatUpdate == null) { return(NotFound()); } if (ModelState.IsValid) { try { var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images/songs"); if (file.Length > 0) { var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); beatUpdate.ArtFilePath = $"/images/songs/{fileName}"; } } } } _context.Update(beatUpdate); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BeatExists(beatUpdate.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details), new { id = beatUpdate.ID })); } return(View(beatArt)); }
public async Task <IActionResult> HeaderImage(int id, UserHeaderImageViewModel userHeader) { if (id != userHeader.ID) { return(NotFound()); } User updateUser = _context.User.Find(userHeader.ID); if (updateUser == null) { return(NotFound()); } if (ModelState.IsValid) { try { var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images/users/profile"); if (file.Length > 0) { var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); updateUser.HeaderImagePath = $"/images/users/profile/{fileName}"; } } } } _context.Update(updateUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(userHeader.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details), new { id = updateUser.ID })); } return(View(userHeader)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Price")] Album album) { if (id != album.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(album); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlbumExists(album.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(album)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,BioInfo,WebsiteUrl")] User user) { if (id != user.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }