Exemple #1
0
        public ActionResult Edit(Booking booking, int id)
        {
            if (booking.CheckIn < DateTime.Today)
            {
                ModelState.AddModelError("CheckIn", "Datum mora biti veci od danasnjeg.");
            }

            if (booking.CheckOut < booking.CheckIn)
            {
                ModelState.AddModelError("CheckOut", "CheckOut mora biti veci od CheckIn-a");
            }

            if (ModelState.IsValid)
            {
                _context.Entry(booking).State = EntityState.Modified;
                _context.SaveChanges();
                BookingHub.RefreshBookings(booking);
                return(RedirectToAction("Index"));
            }

            ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId);
            ViewBag.StayId     = new SelectList(_context.Stays, "Id", "StayName", booking.StayId);

            return(View(booking));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Booking booking = _context.Bookings.Find(id);

            _context.Bookings.Remove(booking);
            _context.SaveChanges();
            BookingHub.RefreshBookings(booking);

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public ActionResult CreateBooking([Bind(Include = "Id,ConsumerId,StayId,CheckIn,CheckOut")] Booking booking)
        {
            var checkIn  = _context.Bookings.Any(b => b.CheckIn == booking.CheckIn);
            var checkOut = _context.Bookings.Any(b => b.CheckOut == booking.CheckOut);
            var stayDb   = _context.Bookings.Any(b => b.StayId == booking.StayId);

            if (checkIn == true && stayDb == true)
            {
                ModelState.AddModelError("CheckIn", "Datum je vec rezervisan");
                ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId);
                ViewBag.StayId     = new SelectList(_context.Stays, "Id", "StayName", booking.StayId);

                return(View(booking));
            }

            if (checkOut == true && stayDb == true)
            {
                ModelState.AddModelError("CheckOut", "Datum je vec rezervisan");
                ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId);
                ViewBag.StayId     = new SelectList(_context.Stays, "Id", "StayName", booking.StayId);

                return(View(booking));
            }

            if (booking.CheckIn < DateTime.Today)
            {
                ModelState.AddModelError("CheckIn", "Datum mora biti veci od danasnjeg.");
            }

            if (booking.CheckOut < booking.CheckIn)
            {
                ModelState.AddModelError("CheckOut", "CheckOut mora biti veci od CheckIn-a");
            }

            if (ModelState.IsValid)
            {
                _context.Bookings.Add(booking);
                _context.SaveChanges();
                BookingHub.RefreshBookings(booking);
                return(RedirectToAction("Index"));
            }

            ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId);
            ViewBag.StayId     = new SelectList(_context.Stays, "Id", "StayName", booking.StayId);

            return(View(booking));
        }