Exemple #1
0
        public ActionResult Create(ReservationViewModels reservationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "The Information is Not Vaild"));
            }
            if (!CheckRoom(reservationViewModel, User.Identity.GetUserId()))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "The Room is Already Reserved please see Reservations"));
            }


            Reservation reservation = new Reservation()
            {
                UserID          = User.Identity.GetUserId(),
                ReservationDate = reservationViewModel.CheckIn,
                DepatureDate    = reservationViewModel.CheckOut,
                Checkout        = false,
                IsApproved      = false,
                IsDeleted       = false,
                LeavingDate     = null,
                ComingDate      = null,
                RoomID          = reservationViewModel.RoomID,
            };

            _reservation.Add(reservation);
            _reservation.CloseTheRoomForReservation(reservationViewModel.RoomID);
            if (_reservation.SaveChanges() > 0)
            {
                //send Data to Desktop Application // if we using signalR
                //var Ihub = GlobalHost.ConnectionManager.GetHubContext<ReservationHub>();
                //Ihub.Clients.All.SendMessage(reservation.RoomID, reservation.UserID,reservation.ReservationDate,reservation.DepatureDate);

                this.roomReposity.SaveChanges();
                return(Json(new { result = true }));
            }
            else
            {
                return(Json(new { result = false }));
            }
        }