public ActionResult Book(Booking booking) { if (ModelState.IsValid) { using (PonyContext db = new PonyContext()) { db.Bookings.Add(booking); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(booking)); }
public ActionResult Book(int id) { PonyContext db = new PonyContext(); Pony pony = db.Ponies.Find(id); Booking booking = new Booking(); ViewBag.Pony = pony.Name; ViewBag.Picture = pony.Picture; ViewBag.PonyID = pony.ID; ViewBag.CustomerID = User.Identity.GetUserId(); booking.Day = DateTime.Today; booking.PonyID = pony.ID; booking.CustomerID = User.Identity.GetUserId(); return(View(booking)); }
public ActionResult Delete(int id, FormCollection collection) { try { using (PonyContext db = new PonyContext()) { Pony pony = db.Ponies.Find(id); if (pony != null) { db.Ponies.Remove(pony); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Index() { using (PonyContext db = new PonyContext()) { var userid = User.Identity.GetUserId(); List <Booking> bookings = db.Bookings.Where(x => x.CustomerID == userid).OrderBy(x => x.Day).ToList(); List <BookingList> bookingsList = new List <BookingList>(); BookingList bookingList; foreach (Booking booking in bookings) { bookingList = new BookingList(); bookingList.Day = booking.Day.ToShortDateString(); bookingList.Session = getSession(booking.Session); bookingList.PonyName = db.Ponies.Find(booking.PonyID).Name; bookingList.PonyPicture = db.Ponies.Find(booking.PonyID).Picture; bookingList.SessionID = booking.ID; bookingsList.Add(bookingList); } return(View(bookingsList)); } }
// GET: BrowsePonies public ActionResult Index() { PonyContext db = new PonyContext(); return(View(db.Ponies.ToList())); }