//Scorepiece is posted, update any changes to the record public async Task <IActionResult> EditScorePiece(int id, [Bind("ScoreId", "Instruments", "IndexedPieces", "names")] ScorePieces scorepiece) { if (ModelState.IsValid) { //Update the record. try { scorepiece.ScoreId = id; _context.Update(scorepiece); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScorePieceExists(scorepiece.ScoreId)) { return(NotFound()); } else { throw; } } return(View(scorepiece)); } //Change view to the original score index screen return(View("Index", "Score")); }
public async Task <IActionResult> EditScore(int id, string search, string genre, string button, [Bind("ScoreId", "Title", "Composer", "Publisher", "SecondaryClassification", "InStock", "Genre", "NumberOfParts", "Notes", "sid")] Score score) { if (ModelState.IsValid) { if (button != null) { //Delete button was selected, attempt to delete the record. if (button.Equals("Delete")) { var toDelete = await _context.Score.FindAsync(id); var toDeleteFromCart = Cart.ShoppingCart.FirstOrDefault(e => e.ScoreId == id); Cart.ShoppingCart.Remove(toDeleteFromCart); 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); } } _context.Score.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } //Update the record. try { score.ScoreId = id; _context.Update(score); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScoreExists(score.ScoreId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("EditScorePiece", "ScorePieces", new { id = score.ScoreId })); } return(RedirectToAction("EditScorePiece", "ScorePieces", new { id = score.ScoreId })); }
public async Task <IActionResult> EditMusician(int id, string button, Musician musician) { if (ModelState.IsValid) { if (button != null) { //Delete button was selected, attempt to delete the record. if (button.Equals("Delete")) { 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.Musician.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } //Attempt to update the record. try { if (musician.MusicianName == null) { return(View()); } musician.MusicianId = id; _context.Update(musician); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicianExists(musician.MusicianId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(musician)); }
public async Task <IActionResult> EditEnsemble(int id, string button, [Bind("EnsembleId", "EnsembleName", "Year", "Conductor")] Ensemble ensemble) { if (button != null) { //Delete the ensemble from the database. if (button.Equals("Delete")) { var toDelete = await _context.Ensemble.FindAsync(id); _context.Remove(toDelete); IEnumerable <EnsemblePlayers> eps = _context.EnsemblePlayers .Where(s => s.EnsembleId == id).ToList(); foreach (EnsemblePlayers ep in eps) { System.Diagnostics.Debug.WriteLine("DELETING"); System.Diagnostics.Debug.WriteLine(ep); _context.EnsemblePlayers.Remove(ep); await _context.SaveChangesAsync(); System.Diagnostics.Debug.WriteLine("AFTER DELETE"); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } //Update the ensemble if (ModelState.IsValid) { try { ensemble.EnsembleId = id; _context.Update(ensemble); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnsembleExists(ensemble.EnsembleId)) { return(NotFound()); } else { throw; } } //Success return(RedirectToAction(nameof(Index))); } return(View(ensemble)); }
public async Task <IActionResult> EditPiece(int id, string button, [Bind("ScoreId", "PieceId", "NumberOfParts")] Piece piece) { if (ModelState.IsValid) { if (button != null) { //Delete button was selected, attempt to delete the record. if (button.Equals("Delete")) { var toDelete = await _context.Piece.FindAsync(id); _context.Piece.Remove(toDelete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } //Update the record. try { piece.PieceId = id; _context.Update(piece); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PieceExists(piece.PieceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(piece)); }
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(); }