Example #1
0
        public IActionResult AddReservation(PlaygroundReservation reservation)
        {
            bool          res       = true;
            DataViewModel dataModel = new DataViewModel();

            if (User.IsInRole("Playground"))
            {
                reservation.Status       = "Accepted";
                reservation.PlaygroundId = _userManager.GetUserId(HttpContext.User);
                dataModel.IsAdmin        = true;
            }
            else
            {
                reservation.Status = "Waiting";
                reservation.UserId = _userManager.GetUserId(HttpContext.User);
                reservation.Name   = _reservationRepository.GetUsername(reservation.UserId);
            }
            if (ModelState.IsValid)
            {
                res = _reservationRepository.Add(reservation);
            }
            if (res)
            {
                dataModel.Reservations = _reservationRepository.GetReservationsByDay(reservation.PlaygroundId, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
                return(PartialView("_Reservation", dataModel));
            }
            else
            {
                return(BadRequest(new BadRequestObjectResult("There is another reservation at the same time, Please change your reservation time.")));
            }
        }
Example #2
0
        private async Task NotifyUser(string playgroundId, PlaygroundReservation acceptedReservation, string msg)
        {
            // creating a new message and saving it to the database
            var sentMsg = _messageRepository.PostMessage(new Message
            {
                Body        = msg,
                MessageDate = DateTime.Now,
                ReceiverId  = acceptedReservation.UserId,
                SenderId    = playgroundId
            });

            var playground = await _userManager.GetUserAsync(User);

            // getting the user that made the reservation request
            // then we change the status of his mesages to true
            ApplicationUser receiver = _userRepository.GetUserById(acceptedReservation.UserId);

            _userRepository.ChangeMsgsStatus(receiver, true);

            // getting the conId of the reserver user and see if he is online
            // if so, i will send a the message in real time
            ConnectedUser receiverConnectedUser = _connectedUsersRepository.GetConnectionIdOfUser(acceptedReservation.UserId);

            if (receiverConnectedUser != null)
            {
                await _hubContext.Clients.Client(receiverConnectedUser.ConnectionId).SendAsync("recMsg", sentMsg.Body, playgroundId, playground.UserName, sentMsg.MessageDate.ToString("dd/MM/yyyy hh:mm:ss tt"));
            }
        }
Example #3
0
        public bool Delete(int id)
        {
            PlaygroundReservation playgroundReservation = _DbContext.playgroundReservations.Find(id);

            if (playgroundReservation != null)
            {
                _DbContext.playgroundReservations.Remove(playgroundReservation);
                _DbContext.SaveChanges();
                return(true);
            }
            return(false);
        }
Example #4
0
 public bool Add(PlaygroundReservation playgroundReservation)
 {
     if (playgroundReservation != null && IsValid(playgroundReservation))
     {
         _DbContext.playgroundReservations.Add(playgroundReservation);
         _DbContext.SaveChanges();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        public bool IsValid(PlaygroundReservation reservation)
        {
            var  allReservations = GetReservationsByDay(reservation.PlaygroundId, reservation.Date.Day, reservation.Date.Month, reservation.Date.Year);
            bool flag            = true;

            foreach (var r in allReservations)
            {
                if ((reservation.StartTime >= r.StartTime && reservation.StartTime < r.EndTime) ||
                    (reservation.EndTime > r.StartTime && reservation.EndTime <= r.EndTime))
                {
                    flag = false;
                    break;
                }
            }
            return(flag);
        }