public ActionResult Book(Booking booking, FormCollection form, bool? reccuringDate) { if (ModelState.IsValid && !Roles.IsUserInRole("Användare")) { var bookingDate = form["datepicker"]; var startTime = form["bookingStartDDL"]; var stoppTime = form["bookingStoppDDL"]; var startDateTime = bookingDate + " " + startTime; var stoppDateTime = bookingDate + " " + stoppTime; booking.StartTime = Convert.ToDateTime(startDateTime); booking.EndTime = Convert.ToDateTime(stoppDateTime); if (booking.EndTime < DateTime.Now || booking.StartTime < DateTime.Now) { ViewBag.Error = "Du kan inte boka DÅTID"; return View(); } if (booking.EndTime <= booking.StartTime) { ViewBag.Error = "Fel bookning START TIME måste vara tidgare än END TIME"; return View(); } if (PreviousBookingExists(booking.RoomID, booking.StartTime, booking.EndTime)) { TempData["UserMessage"] = "Bokningstiden du angav krockar med en existerande bokning."; return RedirectToAction("Index"); } if (reccuringDate == true) { for (int i = 0; i < 3; i++) { switch (i) { case 0: booking.UserID = WebSecurity.CurrentUserId; db.Bookings.InsertOnSubmit(booking); db.SubmitChanges(); break; case 1: Booking booking2 = new Booking(); booking2.StartTime = booking.StartTime.AddDays(7); booking2.EndTime = booking.EndTime.AddDays(7); booking2.RoomID = booking.RoomID; booking2.UserID = WebSecurity.CurrentUserId; db.Bookings.InsertOnSubmit(booking2); db.SubmitChanges(); break; case 2: Booking booking3 = new Booking(); booking3.StartTime = booking.StartTime.AddDays(14); booking3.EndTime = booking.EndTime.AddDays(14); booking3.RoomID = booking.RoomID; booking3.UserID = WebSecurity.CurrentUserId; db.Bookings.InsertOnSubmit(booking3); db.SubmitChanges(); break; } } } else { booking.UserID = WebSecurity.CurrentUserId; db.Bookings.InsertOnSubmit(booking); db.SubmitChanges(); } } else if (ModelState.IsValid) { var bookingDate = form["bookingDateDDL"]; var startTime = form["bookingStartDDL"]; var stoppTime = form["bookingStoppDDL"]; var startDateTime = bookingDate + " " + startTime; var stoppDateTime = bookingDate + " " + stoppTime; booking.StartTime = Convert.ToDateTime(startDateTime); booking.EndTime = Convert.ToDateTime(stoppDateTime); if (booking.EndTime > booking.StartTime.AddHours(4)) { ViewBag.Error = "Bokningstiden får ej överstiga 4 timmar."; return View(); } if (booking.EndTime < booking.StartTime.AddHours(1)) { ViewBag.Error = "Bokningstiden får ej mindre än 1 timma."; return View(); } if (booking.EndTime < DateTime.Now || booking.StartTime < DateTime.Now) { ViewBag.Error = "Du kan inte boka DÅTID"; return View(); } var bookingList = from b in db.Bookings select b.UserID; if (bookingList.Contains(WebSecurity.CurrentUserId)) { TempData["UserMessage"] = "Du har redan gjort en bokning!"; return RedirectToAction("Index"); } if (PreviousBookingExists(booking.RoomID, booking.StartTime, booking.EndTime)) { TempData["UserMessage"] = "Bokningstiden du angav krockar med en existerande bokning."; return RedirectToAction("Index"); } booking.UserID = WebSecurity.CurrentUserId; db.Bookings.InsertOnSubmit(booking); db.SubmitChanges(); } return RedirectToAction("Index"); }
private void detach_Bookings(Booking entity) { this.SendPropertyChanging(); entity.Room = null; }
private void attach_Bookings(Booking entity) { this.SendPropertyChanging(); entity.Room = this; }
partial void DeleteBooking(Booking instance);
partial void UpdateBooking(Booking instance);
partial void InsertBooking(Booking instance);