public async Task <IActionResult> Edit(Guid id, [Bind("UserId,CompositionId,Date")] FavouriteSongs favouriteSongs) { if (id != favouriteSongs.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(favouriteSongs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FavouriteSongsExists(favouriteSongs.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CompositionId"] = new SelectList(_context.Composition, "CompositionId", "CompositionId", favouriteSongs.CompositionId); ViewData["UserId"] = new SelectList(_context.User, "UserId", "Email", favouriteSongs.UserId); return(View(favouriteSongs)); }
public async Task <IActionResult> Add(Guid CompositionId) { if (ModelState.IsValid) { FavouriteSongs favouriteSong = new FavouriteSongs(); favouriteSong.UserId = new Guid(User.FindFirst(x => x.Type == "id").Value); favouriteSong.CompositionId = CompositionId; _context.FavouriteSongs.Add(favouriteSong); await _context.SaveChangesAsync(); return(Redirect(Request.Headers["Referer"].ToString())); } return(Redirect(Request.Headers["Referer"].ToString())); }
public async Task <IActionResult> Create([Bind("UserId,CompositionId,Date")] FavouriteSongs favouriteSongs) { if (ModelState.IsValid) { favouriteSongs.UserId = Guid.NewGuid(); _context.Add(favouriteSongs); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CompositionId"] = new SelectList(_context.Composition, "CompositionId", "CompositionId", favouriteSongs.CompositionId); ViewData["UserId"] = new SelectList(_context.User, "UserId", "Email", favouriteSongs.UserId); return(View(favouriteSongs)); }