public async Task <IActionResult> Create([Bind("BookingId,UserId,LectureId")] Booking booking) { bool waitListFound = false; if (ModelState.IsValid) { Lecture l = _context.Lecture.FindAsync(booking.LectureId).Result; if (l.Spaces < 1) { booking.WaitList = 1; //WaitListsController wlCon = new WaitListsController(_context); //WaitList wl = new WaitList(booking); //wlCon.Create(wl); //return RedirectToAction(nameof(Index)); waitListFound = true; } _context.Add(booking); await _context.SaveChangesAsync(); if (waitListFound == false) { LecturesController con = new LecturesController(_context); con.Edit(booking.LectureId, _context.Lecture.FindAsync(booking.LectureId).Result); } //CreateUpdateLecture(booking); return(RedirectToAction(nameof(Index))); } ViewData["LectureId"] = new SelectList(_context.Lecture, "LectureId", "Title", booking.LectureId); ViewData["UserId"] = new SelectList(_context.User, "UserId", "Email", booking.UserId); return(View(booking)); }
private bool CreateUpdateLecture(Booking b) { LecturesController con = new LecturesController(_context); foreach (var lecture in _context.Lecture) { if (b.LectureId == lecture.LectureId) { con.Edit(b.LectureId, lecture); return(true); } } return(false); }
public async Task <IActionResult> DeleteConfirmed(int id) { bool waitListFound = false; Booking waitBooking = new Booking(); var booking = await _context.Booking.FindAsync(id); int delLecture = booking.LectureId; _context.Booking.Remove(booking); await _context.SaveChangesAsync(); foreach (var booking1 in _context.Booking) { if (booking1.LectureId == delLecture && booking1.WaitList == 1) { waitBooking = booking1; waitBooking.WaitList = 0; waitListFound = true; break; } } if (waitListFound == true) { Edit(waitBooking.LectureId, waitBooking); } else { LecturesController con = new LecturesController(_context); con.Edit(delLecture, _context.Lecture.FindAsync(delLecture).Result); } //Flyt op return(RedirectToAction(nameof(Index))); }