Exemple #1
0
        public async Task <IActionResult> AcceptReservation(int id)
        {
            var dataModel = new DataViewModel();

            _reservationRepository.AcceptReservation(id);
            var playgroundId        = _userManager.GetUserId(User);
            var acceptedReservation = _reservationRepository.GetAll(playgroundId).FirstOrDefault(r => r.Id == id);

            // notifing the accepted request user whether their request to reserve is accepted or not
            await NotifyUser(playgroundId, acceptedReservation, $"Your reservation request has been approved for {acceptedReservation.Date} day from {acceptedReservation.StartTime} to {acceptedReservation.EndTime}");

            //check for another requests and delete the requests with the same time of another reservation
            var remainingRequests = _reservationRepository.GetRequests(playgroundId);

            foreach (var r in remainingRequests)
            {
                if (_reservationRepository.IsValid(r) == false)
                {
                    // notifing the other users that thier requests have been rejected
                    await NotifyUser(playgroundId, r, $"Sorry, your reservation request has been rejected  for {r.Date} day from {r.StartTime} to {r.EndTime}");

                    _reservationRepository.Delete(r.Id);
                }
            }
            dataModel.Requests = _reservationRepository.GetRequests(playgroundId);
            dataModel.IsAdmin  = true;
            return(PartialView("_Request", dataModel));
        }
        public IViewComponentResult Invoke(DataViewModel dataModel)
        {
            string userId = null;

            if (dataModel.Entity != null)
            {
                userId = dataModel.Entity.Id;
            }
            else if (dataModel.Entity == null)
            {
                userId           = dataModel.CurrentUser.Id;
                dataModel.Entity = dataModel.CurrentUser;
            }
            var requests          = _repository.GetRequests(userId);
            var todayReservations = _repository.GetReservationsByDay(userId, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year).OrderBy(c => c.StartTime);
            var allReservations   = _repository.GetAll(userId);

            dataModel.Reservations    = todayReservations;
            dataModel.Requests        = requests;
            dataModel.AllReservations = allReservations;
            return(View("/Components/Reservation/Reservation.cshtml", dataModel));
        }