Exemplo n.º 1
0
 public ActionResult Edit(MyBooking mybooking)
 {
     if (ModelState.IsValid)
     {
         var Check = (mybooking.BookingDate - DateTime.Now).TotalDays;
         if (Check > 15)
         {
             db.Entry(mybooking).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("MyBookings"));
         }
         else
         {
             ViewBag.Sorry = "Sorry, You can't edit your booking in less than 15 days of booking date";
         }
     }
     return(View());
 }
Exemplo n.º 2
0
        public ActionResult Details(int id)
        {
            MyBooking booking = db.MyBookings.Single(a => a.Id == id);

            return(View(booking));
        }
        public ActionResult Book(MyBooking booking)
        {
            int id = (int)Session["HallId"];

            ViewBag.BookedDays = db.MyBookings.Where(a => a.HallId == id).Select(a => a.BookingDate).ToList();


            ViewBag.Service1 = db.Halls.Where(a => a.Id == id).Select(a => a.AdditionalService).Single();
            ViewBag.Service2 = db.Halls.Where(a => a.Id == id).Select(a => a.Service2).Single();
            ViewBag.Service3 = db.Halls.Where(a => a.Id == id).Select(a => a.Service3).Single();
            ViewBag.Service4 = db.Halls.Where(a => a.Id == id).Select(a => a.Service4).Single();
            ViewBag.Service5 = db.Halls.Where(a => a.Id == id).Select(a => a.Service5).Single();
            ViewBag.Service6 = db.Halls.Where(a => a.Id == id).Select(a => a.Service6).Single();
            ViewBag.Service7 = db.Halls.Where(a => a.Id == id).Select(a => a.Service7).Single();
            ViewBag.Service8 = db.Halls.Where(a => a.Id == id).Select(a => a.Service8).Single();
            ViewBag.Service9 = db.Halls.Where(a => a.Id == id).Select(a => a.Service9).Single();
            booking.HallId   = id;
            booking.UserId   = User.Identity.GetUserId();
            if (ModelState.IsValid)
            {
                char[]   seperator    = { ':' };
                string   s            = db.MyBookings.Where(a => a.HallId == id && a.BookingDate == booking.BookingDate).Select(a => a.StartTime).Single();
                string[] StartDbArray = s.Split(seperator);
                int      DbStart      = Convert.ToInt32(StartDbArray[0]);
                string   e            = db.MyBookings.Where(a => a.HallId == id && a.BookingDate == booking.BookingDate).Select(a => a.EndTime).Single();
                string[] EndDbArray   = e.Split(seperator);
                int      DbEnd        = Convert.ToInt32(EndDbArray[0]);

                string[] StartBookingArray = booking.StartTime.Split(seperator);
                int      bookingStart      = int.Parse(StartBookingArray[0]);

                string[] EndBookingArray = booking.EndTime.Split(seperator);
                int      bookingEnd      = int.Parse(EndBookingArray[0]);

                if (bookingStart > DbStart && bookingEnd < DbEnd)
                {
                    ViewBag.Failure = "Sorry, the hall is booked during this interval";
                }
                else if (bookingStart < DbStart && bookingEnd > DbStart)
                {
                    ViewBag.Failure = "Sorry, the hall is booked during this interval";
                }
                else
                {
                    db.MyBookings.Add(booking);
                    db.SaveChanges();
                    ViewBag.Success = "The Hall Booked Successfully";
                }

                //int Checking = db.MyBookings.Where(a => a.BookingDate == booking.BookingDate && a.HallId == booking.HallId).Count();
                //if (Checking < 1)
                //{
                //    db.MyBookings.Add(booking);
                //    db.SaveChanges();
                //    ViewBag.Success = "The Hall Booked Successfully";
                //}
                //else
                //{
                //    ViewBag.Failure = "Sorry, The Hall is booked during this day";

                //}
            }

            return(View(booking));
        }