public async Task <IActionResult> Repair(RepairViewModel repairLoan) { string insertToRepairs = "Insert into Repairs values (" + repairLoan.InstrumentInventoryId.ToString() + ", (select top 1 [Technician ID] from Technician), GETDATE(), '" + repairLoan.Notes + "' , null)"; var repairResult = _context.Database.ExecuteSqlCommand(insertToRepairs); //Give out new loan string proc = "[Loan Instrument] " + repairLoan.EnrollmentId.ToString(); var loanResult = _context.Database.ExecuteSqlCommand(proc); //Return loan var loan = await _context.Loan .Include(l => l.Enrollment) .Include(l => l.InstrumentInventory) .FirstOrDefaultAsync(m => m.EnrollmentId == repairLoan.EnrollmentId && m.InstrumentInventoryId == repairLoan.InstrumentInventoryId && m.DateReturned == null); loan.DateReturned = DateTime.Today; string feedbackString = REPAIR_SUCCESS; string colorString = "green"; if (loanResult < 1) { feedbackString = LOAN_ERROR; colorString = "red"; } else if (repairResult < 1) { feedbackString = REPAIR_ERROR; colorString = "red"; } if (ModelState.IsValid) { try { _context.Update(loan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoanExists(loan.InstrumentInventoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Feedback", new { feedback = feedbackString, color = colorString })); } return(RedirectToAction("Feedback", new { feedback = feedbackString, color = colorString })); }
public async Task <IActionResult> Create(PerformancePiece performancePiece) { Piece piece = await _context.Piece.FindAsync(performancePiece.PieceId); piece.LastPerformedDate = DateTime.Now; _context.Update(piece); await _context.SaveChangesAsync(); _context.Add(performancePiece); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Performances")); }
public async Task <IActionResult> Edit(int id, [Bind("ContactId,Email,Phone")] Contact contact) { if (id != contact.ContactId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contact); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(contact.ContactId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task <IActionResult> Edit(int id, [Bind("PayrollId,StaffId,Date,Amount,Notes")] Payroll payroll) { if (id != payroll.PayrollId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(payroll); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PayrollExists(payroll.PayrollId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["StaffId"] = new SelectList(_context.Staff, "StaffId", "StaffId", payroll.StaffId); return(View(payroll)); }
public async Task <IActionResult> Edit(int id, [Bind("InstrumentInventoryId,InstrumentId,PurchaseDate,Manufacturer,Cost")] InstrumentInventory instrumentInventory) { if (id != instrumentInventory.InstrumentInventoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(instrumentInventory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstrumentInventoryExists(instrumentInventory.InstrumentInventoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["InstrumentId"] = new SelectList(_context.Instrument, "InstrumentId", "Instrument1", instrumentInventory.InstrumentId); return(View(instrumentInventory)); }
public async Task <IActionResult> Edit(Repairs repairToClose) { var repairs = await _context.Repairs .Include(r => r.InstrumentInventory) .Include(r => r.Technician) .FirstAsync(m => m.TechnicianId == repairToClose.TechnicianId && m.InstrumentInventoryId == repairToClose.InstrumentInventoryId && m.RepairEnd == null); repairs.RepairEnd = DateTime.Now; if (ModelState.IsValid) { try { _context.Update(repairs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RepairsExists(repairs.InstrumentInventoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["InstrumentInventoryId"] = new SelectList(_context.InstrumentInventory, "InstrumentInventoryId", "Manufacturer", repairs.InstrumentInventoryId); ViewData["TechnicianId"] = new SelectList(_context.Technician, "TechnicianId", "TechnicianId", repairs.TechnicianId); return(View(repairs)); }
public async Task <IActionResult> Edit(int id, StudentEditViewModel model) { var student = await _context.Student .Include(s => s.Person) .Include(s => s.Contact) .FirstOrDefaultAsync(m => m.StudentId == id); student.Person.FirstName = model.FirstName; student.Person.LastName = model.LastName; student.Person.Dob = model.Dob; student.Person.Address = model.Address; if (model.Email != null) { if (student.ContactId == null) { Contact contact = new Contact(); contact.Email = model.Email; contact.Phone = model.Phone; _context.Contact.Add(contact); _context.SaveChanges(); student.Contact = contact; } else { student.Contact.Email = model.Email; student.Contact.Phone = model.Phone; } } _context.Update(student); _context.SaveChanges(); return(RedirectToAction("Details", new { id = student.StudentId })); }
public async Task <IActionResult> Edit(int id, [Bind("VenueId,VenueName")] Venue venue) { if (id != venue.VenueId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(venue); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VenueExists(venue.VenueId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(venue)); }
public async Task <IActionResult> Edit(int id, [Bind("EnsembleId,Type")] Ensemble ensemble) { if (id != ensemble.EnsembleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ensemble); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnsembleExists(ensemble.EnsembleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ensemble)); }
public async Task <IActionResult> Edit(int id, [Bind("PerformanceId,Date,Time,VenueId")] Performance performance) { if (id != performance.PerformanceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(performance); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PerformanceExists(performance.PerformanceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["VenueId"] = new SelectList(_context.Venue, "VenueId", "VenueId", performance.VenueId); return(View(performance)); }
public async Task <IActionResult> Edit(int id, [Bind("PieceId,Title,Composer,LastPerformedDate")] Piece piece) { if (id != piece.PieceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(piece); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PieceExists(piece.PieceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(piece)); }
public async Task <IActionResult> Edit(int id, [Bind("PersonId,FirstName,LastName,Dob,Address")] Person person) { if (id != person.PersonId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(person); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(person.PersonId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Edit(int id, [Bind("InstrumentId,Instrument1,StudentFee,OpenFee,HireFee,HeadTutor")] Instrument instrument) { if (id != instrument.InstrumentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(instrument); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstrumentExists(instrument.InstrumentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["HeadTutor"] = new SelectList(_context.Tutor, "TutorId", "TutorId", instrument.HeadTutor); return(View(instrument)); }
public async Task <IActionResult> Edit(int id, [Bind("LocalMusiciansId,ContactId,FirstName,LastName")] LocalMusicians localMusicians) { if (id != localMusicians.LocalMusiciansId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(localMusicians); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocalMusiciansExists(localMusicians.LocalMusiciansId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ContactId"] = new SelectList(_context.Contact, "ContactId", "Email", localMusicians.ContactId); return(View(localMusicians)); }
public async Task <IActionResult> Edit(int id, [Bind("EnsembleId,PerformanceId")] EnsemblePerformance ensemblePerformance) { if (id != ensemblePerformance.EnsembleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ensemblePerformance); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnsemblePerformanceExists(ensemblePerformance.EnsembleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EnsembleId"] = new SelectList(_context.Ensemble, "EnsembleId", "Type", ensemblePerformance.EnsembleId); ViewData["PerformanceId"] = new SelectList(_context.Performance, "PerformanceId", "PerformanceId", ensemblePerformance.PerformanceId); return(View(ensemblePerformance)); }
public async Task <IActionResult> Edit(int id, [Bind("SheetMusicId,Title,Composer,Amount")] SheetMusic sm) { SheetMusic sheetMusic = await _context.SheetMusic.FindAsync(id); sheetMusic.Amount = sm.Amount; if (id != sheetMusic.SheetMusicId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(sheetMusic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SheetMusicExists(sheetMusic.SheetMusicId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(sheetMusic)); }
public async Task <IActionResult> Edit([Bind("EnrollmentId,MusicClassId,Date")] EnrollmentMusicClass enrollmentMusicClass) { System.Diagnostics.Debug.WriteLine(enrollmentMusicClass.EnrollmentId); if (ModelState.IsValid) { try { _context.Update(enrollmentMusicClass); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnrollmentMusicClassExists(enrollmentMusicClass.EnrollmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EnrollmentId"] = new SelectList(_context.Enrollment, "EnrollmentId", "EnrollmentId", enrollmentMusicClass.EnrollmentId); ViewData["MusicClassId"] = new SelectList(_context.MusicClass, "MusicClassId", "MusicClassId", enrollmentMusicClass.MusicClassId); return(View(enrollmentMusicClass)); }
public async Task <IActionResult> Create([Bind("SheetMusicTutorId,SheetMusicId,TutorId,AmountLoaned")] SheetMusicTutor sheetMusicTutor) { sheetMusicTutor.DateLoaned = DateTime.Now; SheetMusic sm = await _context.SheetMusic.FirstOrDefaultAsync(s => s.SheetMusicId == sheetMusicTutor.SheetMusicId); sm.Amount -= sheetMusicTutor.AmountLoaned; if (sm.Amount >= 0) { if (ModelState.IsValid) { _context.Update(sm); _context.Add(sheetMusicTutor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { ViewData["Error"] = "Not enough copies to loan. Can only loan out copies in stock."; } List <SheetMusic> sheetMusic = _context.SheetMusic.ToList(); List <SheetMusicViewModel> sms = sheetMusic.Select(s => new SheetMusicViewModel { id = s.SheetMusicId, name = s.Title + " (" + s.Composer + ") - Quantity: " + (sm.Amount += sheetMusicTutor.AmountLoaned) }).ToList(); ViewData["SheetMusic"] = new SelectList(sms, "id", "name"); List <Tutor> tutors = _context.Tutor.Include(a => a.Staff.Person).ToList(); List <TutorViewModel> t = tutors.Select(s => new TutorViewModel { id = s.TutorId, name = s.Staff.Person.FirstName + " " + s.Staff.Person.LastName }).ToList(); ViewData["Tutor"] = new SelectList(t, "id", "name"); return(View(sheetMusicTutor)); }
public async Task <IActionResult> Edit(int id, [Bind("TutorId,InstrumentId,MaxGrade")] TutorType tutorType) { TutorType tutorT = await _context.TutorType.FindAsync(id); tutorT.MaxGrade = tutorType.MaxGrade; tutorT.InstrumentId = tutorType.InstrumentId; tutorT.Instrument = tutorType.Instrument; tutorT.TutorId = tutorType.TutorId; tutorT.Tutor = tutorType.Tutor; _context.Update(tutorT); if (id != tutorT.TutorTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tutorT); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TutorTypeExists(tutorT.TutorTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["InstrumentId"] = new SelectList(_context.Instrument, "InstrumentId", "Instrument1", tutorType.InstrumentId); ViewData["TutorId"] = new SelectList(_context.Tutor, "TutorId", "TutorId", tutorType.TutorId); return(View(tutorType)); }
public async Task <IActionResult> Edit(int id, TutorCreateViewModel model) { var tutor = await _context.Tutor .Include(t => t.Staff) .ThenInclude(s => s.Person) .Include(t => t.Staff) .ThenInclude(s => s.Contact) .FirstOrDefaultAsync(m => m.TutorId == id); tutor.Staff.Person.FirstName = model.FirstName; tutor.Staff.Person.LastName = model.LastName; tutor.Staff.Person.Dob = model.Dob; tutor.Staff.Person.Address = model.Address; tutor.Staff.Contact.Email = model.Email; tutor.Staff.Contact.Phone = model.Phone; tutor.Staff.Hours = model.Hours; _context.Update(tutor); _context.SaveChanges(); return(RedirectToAction("Details", new { id = tutor.TutorId })); }
public async Task <IActionResult> Edit(int id, [Bind("MusicClassId,TutorId,LessonTimeId,StartDate,EndDate")] MusicClass mc) { var musicClass = await _context.MusicClass .Include(m => m.LessonTime) .Include(m => m.Tutor) .FirstOrDefaultAsync(m => m.MusicClassId == id); musicClass.LessonTimeId = mc.LessonTimeId; musicClass.TutorId = mc.TutorId; if (id != musicClass.MusicClassId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(musicClass); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicClassExists(musicClass.MusicClassId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LessonTimeId"] = new SelectList(_context.LessonTime, "LessonTimeId", "LessonTimeId", musicClass.LessonTimeId); ViewData["TutorId"] = new SelectList(_context.Tutor, "TutorId", "TutorId", musicClass.TutorId); return(View(musicClass)); }
public async Task <IActionResult> Edit(int id, [Bind("EnrollmentId,StudentId,InstrumentId,Grade,Date,Paid")] Enrollment enrollment) { if (id != enrollment.EnrollmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(enrollment); await _context.SaveChangesAsync(); } catch (Exception e) { if (e is SqlException | e is DbUpdateException) { return(RedirectToAction("LoanError", new { errorMessage = "Can't update Enrollment, enrollment already exists." })); } if (!EnrollmentExists(enrollment.EnrollmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["InstrumentId"] = new SelectList(_context.Instrument, "InstrumentId", "Instrument1", enrollment.InstrumentId); ViewData["StudentId"] = new SelectList(_context.Student, "StudentId", "StudentId", enrollment.StudentId); return(View(enrollment)); }
public async Task <IActionResult> Edit(int id, StaffViewModel model) { var staff = await _context.Staff .Include(s => s.Person) .Include(s => s.Contact) .FirstOrDefaultAsync(m => m.StaffId == id); staff.Person.FirstName = model.FirstName; staff.Person.LastName = model.LastName; staff.Person.Dob = model.Dob; staff.Person.Address = model.Address; staff.Contact.Email = model.Email; staff.Contact.Phone = model.Phone; staff.Hours = model.Hours; staff.StartDate = model.StartDate; if (model.LeftDate != null) { staff.LeftDate = model.LeftDate; } _context.Update(staff); _context.SaveChanges(); return(RedirectToAction("Details", new { id = staff.StaffId })); }