daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Jan 18th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Error: There is already an open DataReader associated with this Command which must be closed first.
  2.    
  3. Line 51:             @Html.DropDownList("ScreeningId", null, htmlAttributes: new { @class = "form-control" })
  4.    
  5. public class ReservationsController : Controller
  6. {
  7.     private AppDbContext db = new AppDbContext();
  8.  
  9.     // GET: Reservations
  10.     public ActionResult Index()
  11.     {
  12.         return View(db.Reservations.ToList());
  13.     }
  14.  
  15.     // GET: Reservations/Create
  16.     public ActionResult Create()
  17.     {
  18.         ViewBag.ScreeningId = new SelectList(db.Screenings, "Id", "Description");
  19.  
  20.         HashSet<int> seats = new HashSet<int>(db.Reservations.Select(x => x.SeatNumber));
  21.         ViewBag.Seats = seats;
  22.         return View();
  23.     }
  24.  
  25.     // POST: Reservations/Create
  26.     [HttpPost]
  27.     [ValidateAntiForgeryToken]
  28.     public ActionResult Create([Bind(Include = "Id,FirstName,SecondName,Phone,SeatNumber,ScreeningId")] Reservation reservation)
  29.     {
  30.         ViewBag.ScreeningId = new SelectList(db.Screenings, "Id", "Description");
  31.         if (ModelState.IsValid)
  32.             {
  33.  
  34.             // sprawdzamy czy miejsce bylo juz zajete
  35.             if (db.Reservations.Select(x => x.SeatNumber).Contains(reservation.SeatNumber))
  36.             {
  37.  
  38.                 return View(reservation);
  39.             }
  40.             else
  41.             {
  42.                 db.Reservations.Add(reservation);
  43.                 db.SaveChanges();
  44.             }
  45.             if (Session["Login"] != null)
  46.             {
  47.                 return RedirectToAction("Index");
  48.             }
  49.             return RedirectToAction("Success");
  50.         }
  51.  
  52.         return View(reservation);
  53.     }
  54.    
  55. <div class="form-group">
  56.     @Html.LabelFor(model => model.Screening, "Seans", htmlAttributes: new { @class = "control-label col-md-2" })
  57.     <div class="col-md-10">
  58.         @Html.DropDownList("ScreeningId", null, htmlAttributes: new { @class = "form-control" })
  59.         @Html.ValidationMessageFor(model => model.Screening, "", new { @class = "text-danger" })
  60.     </div>
  61. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top