public async Task <IActionResult> Create([Bind("Id,GroundId,ReservationDate")] GroundReservation groundReservation)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            groundReservation.UserId = user.Id;
            if (ModelState.IsValid)
            {
                if (groundReservation.ReservationDate == DateTime.Now.Date)
                {
                    ModelState.AddModelError("ReservationDate", "Today's Booking cannot be done! please select another date");
                }
                if (groundReservation.ReservationDate < DateTime.Now.Date)
                {
                    ModelState.AddModelError("ReservationDate", "You have Entered a Back Date Entry which is not Allowed");
                }
                var x = _context.GroundReservation.Where(xx => xx.ReservationDate == groundReservation.ReservationDate && xx.GroundId == groundReservation.GroundId).Any();
                if (x == true)
                {
                    ModelState.AddModelError("ReservationDate", "This Date is already booked!");
                    ViewData["GroundId"] = new SelectList(_context.Ground, "Id", "Name", groundReservation.GroundId);
                    return(View(groundReservation));
                }
                _context.Add(groundReservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroundId"] = new SelectList(_context.Ground, "Id", "Name", groundReservation.GroundId);
            //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", groundReservation.UserId);
            return(View(groundReservation));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,GroundId,ReservationDate")] GroundReservation groundReservation)
        {
            if (id != groundReservation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(groundReservation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroundReservationExists(groundReservation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroundId"] = new SelectList(_context.Ground, "Id", "Address", groundReservation.GroundId);
            ViewData["UserId"]   = new SelectList(_context.Users, "Id", "Id", groundReservation.UserId);
            return(View(groundReservation));
        }
 public IActionResult CheckGroundAvailability([Bind("GroundId,ReservationDate")] GroundReservation groundReservation)
 {
     if (ModelState.IsValid)
     {
         if (groundReservation.ReservationDate <= DateTime.Now.Date)
         {
             ModelState.AddModelError("ReservationDate", "You have Entered a Back Date Entry which is not Allowed");
         }
         var x = _context.GroundReservation.Where(xx => xx.ReservationDate == groundReservation.ReservationDate && xx.GroundId == groundReservation.GroundId).Any();
         if (x == true)
         {
             ModelState.AddModelError("ReservationDate", "This Ground is already booked on Selected Date!");
         }
         else
         {
             ModelState.AddModelError("ReservationDate", "The Ground is Available for Booking on selected Date");
         }
     }
     ViewData["GroundId"] = new SelectList(_context.Ground, "Id", "Name", groundReservation.GroundId);
     return(View(groundReservation));
 }