//Simply delete a score by id. public async Task <IActionResult> Delete(int id) { foreach (Piece piece in _context.Piece) { if (piece.ScoreId == id) { var pieceDelete = await _context.Piece.FindAsync(piece.PieceId); IEnumerable <CheckedOut> coDelete = from co in _context.CheckedOut where co.PartId == piece.PieceId select co; foreach (CheckedOut cod in coDelete) { _context.CheckedOut.Remove(cod); } _context.Piece.Remove(pieceDelete); } } var toDelete = await _context.Score.FindAsync(id); var toDeleteFromCart = Cart.ShoppingCart.FirstOrDefault(e => e.ScoreId == id); Cart.ShoppingCart.Remove(toDeleteFromCart); _context.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
// GET: Ensemble/RemoveFrom //Takes an ensemble and musician by id, and removes the musician from //the ensemble. public async Task <IActionResult> RemoveFrom(int ens, int mus) { EnsemblePlayers ensemblePlayer; try { ensemblePlayer = _context.EnsemblePlayers.First(e => e.EnsembleId == ens && e.MusicianId == mus); } catch { return(NotFound()); } _context.Remove(ensemblePlayer); await _context.SaveChangesAsync(); return(RedirectToAction("Musicians", new { id = ens })); }
//Simply delete a score by id. public async Task <IActionResult> Delete(int id) { var toDelete = await _context.Piece.FindAsync(id); _context.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void Return(int pieceId, int musicianId, String cond) { Piece p = _context.Piece.Find(pieceId); CheckedOut co = _context.CheckedOut.Find(musicianId, pieceId); float rating; if (cond.Equals("Excellent")) { rating = 5; } else if (cond.Equals("Good")) { rating = 4; } else if (cond.Equals("Fair")) { rating = 3; } else if (cond.Equals("Poor")) { rating = 2; } else if (cond.Equals("Awful")) { rating = 1; } else { _context.Remove(co); _context.SaveChanges(); return; } //The new rating will be the weighted average of the old rating with the condition of the returned part. float newRating = (p.AggregateRating * (p.NumberofParts - 1) + rating) / p.NumberofParts; p.AggregateRating = newRating; _context.Update(p); _context.Remove(co); _context.SaveChanges(); }
//Simply delete a musician by id. public async Task <IActionResult> Delete(int id) { var toDelete = await _context.Musician.FindAsync(id); IEnumerable <EnsemblePlayers> eps = _context.EnsemblePlayers .Where(s => s.MusicianId == id).ToList(); foreach (EnsemblePlayers ep in eps) { _context.EnsemblePlayers.Remove(ep); } _context.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }