public RoomReservavtionTests()
 {
     _hotel           = Substitute.For <IHotel>();
     _hotel.Rooms     = HotelRooms();
     _findFreeRoom    = Substitute.For <IFindRoom>();
     _roomReservation = new RoomReservation(_hotel, _findFreeRoom);
 }
Example #2
0
        public bool ReserveRoom(RoomReservation aRoomReservation)
        {
            var data = new RoomReservationRepository();

            data.ReserveRoom(aRoomReservation);
            return(true);
        }
Example #3
0
        public Task ReserveRoom
            (IDialogContext context, LuisResult result)
        {
            var roomReservation = new RoomReservation();

            // 取得unit的entity
            var unitEntity = result.Entities
                             .FirstOrDefault(x => x.Type == "unit");

            // 有表示會給預設住多久
            if (unitEntity != null)
            {
                var numberEntity = result.Entities
                                   .FirstOrDefault(x => x.Type == "builtin.number");

                var number = int.Parse(numberEntity.Entity);

                // 如果單位是 天,表示實際住的晚上天數會減少1
                if (unitEntity.Entity == "天")
                {
                    number = number - 1;
                }

                roomReservation.NumberOfNightToStay = number;
            }

            context.Call(new ReserveRoomDialog(roomReservation),
                         ReserverRoomAfterAsync);

            return(Task.CompletedTask);
        }
        public async Task <int> UpdateReservation(RoomReservation Reservation)
        {
            db.RoomReservationRepo.Update(Reservation.ReservationCode, Reservation);
            int Check = await db.Save();

            return(Check);
        }
 public ActionResult ChooseData(RoomReservation roomReservation)
 {
     roomReservation.Confirmation = false;
     ViewBag.UserId = User.Identity.GetUserId();
     ViewBag.RoomId = roomReservation.RoomId;
     if (roomReservation.TimeStart < DateTime.Now)
     {
         ViewBag.error = "Неккоректное начальное время";
         return(View());
     }
     if (roomReservation.TimeStart > roomReservation.TimeEnd)
     {
         ViewBag.error = "Неккоректно введены данные";
         return(View());
     }
     foreach (var rr in mrc.RoomReservations.ToList())
     {
         if (roomReservation.RoomId == rr.RoomId && rr.Confirmation)
         {
             if (!((roomReservation.TimeStart < rr.TimeStart && roomReservation.TimeEnd <= rr.TimeStart) ||
                   (roomReservation.TimeStart >= rr.TimeEnd && roomReservation.TimeEnd > rr.TimeEnd)))
             {
                 ViewBag.error = "Данное время занято";
                 return(View());
             }
         }
     }
     mrc.RoomReservations.Add(roomReservation);
     mrc.SaveChanges();
     return(RedirectToAction("RoomDescription", "Home", roomReservation.RoomId));
 }
Example #6
0
        public async Task <IActionResult> PutRoomReservation([FromRoute] long id, [FromBody] RoomReservation roomReservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roomReservation.ReservationId)
            {
                return(BadRequest());
            }

            _context.Entry(roomReservation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomReservationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult> NewReservation(AdminNewReservation Data)
        {
            int   result;
            Guest guest = new Guest {
                GuestCode    = 0,
                GuestName    = Data.GuestName,
                NationalID   = Data.NationalID,
                Nationality  = Data.Nationality,
                PhoneNumber  = Data.PhoneNumber,
                Gender       = Data.Gender,
                GuestAddress = Data.GuestAddress
            };

            if (Data.GuestCode != 0)
            {
                guest.GuestCode = Data.GuestCode;
                result          = await GuestStore.UpdateGuest(guest.GuestCode, guest);
            }
            else
            {
                result = await GuestStore.AddGuest(guest);
            }
            guest = GuestStore.GetGuestByNationalId(Data.NationalID);
            RoomReservation roomReservation = new RoomReservation {
                StartDate = Data.StartDate,
                EndDate   = Data.EndDate,
                RoomID    = Data.RoomID,
                GuestID   = guest.GuestCode
            };

            result = await RoomReservationstore.CreatNewReservation(roomReservation);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public async Task <IActionResult> PostRoomReservation([FromRoute] long id,
                                                              [FromRoute] long roomNumber,
                                                              [FromRoute] long reservationId,
                                                              [FromBody] RoomReservation roomReservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.RoomReservations.Add(roomReservation);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (roomReservationExists(id, roomNumber, reservationId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRoomReservation", new { id = roomReservation.RoomNumber },
                                   roomReservation));
        }
Example #9
0
        //[Authorize(Roles = "AppUser")]
        public IHttpActionResult PostRoomReservation(RoomReservation roomReservation)
        {
            RoomReservation rr = new RoomReservation();

            rr.Room = new Room {
                RoomNumber = 333
            };
            rr.Id   = roomReservation.Id;
            rr.User = new BAIdentityUser {
                Id = "User1"
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (RoomReservationExists(roomReservation.Id))
            {
                return(BadRequest());
            }

            try
            {
                db.RoomReservations.Add(rr);
                db.SaveChanges();
                return(Ok(rr));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(StatusCode(HttpStatusCode.ExpectationFailed));
            }
        }
        public async Task <IActionResult> MakeRoomReservation(RoomReservation reservation)
        {
            if (reservation.Date == default)
            {
                return(View());
            }

            var currentDate = new DateTime();
            var email       = User.Identity.Name;
            var customer    = await _context.Customers.FirstOrDefaultAsync(x => x.Email == email);

            var roomReservation = await _context.RoomReservations.Include(x => x.Customer).FirstOrDefaultAsync(x =>
                                                                                                               x.Customer.Email == email && x.Date >= currentDate);

            if (roomReservation != null)
            {
                ViewData["Error"] = "You have a reservation already";
                return(View());
            }

            reservation.Customer = customer;
            _context.RoomReservations.Add(reservation);
            await _context.SaveChangesAsync();

            return(RedirectToAction("RoomReservations"));
        }
Example #11
0
        public IActionResult Index(BookRoom confirmBooking, String btnbookroom)
        {
            var   roomName   = _motelContext.RoomTypes.Where(p => p.RoomName == btnbookroom).Select(p => p.RoomName).FirstOrDefault();
            var   roomTypeID = _motelContext.RoomTypes.Where(p => p.RoomName == roomName).Select(x => x.ID).FirstOrDefault();
            var   guestID    = _motelContext.Guests.Where(p => p.FirstName == confirmBooking.firstName && p.LastName == confirmBooking.lastName).Select(x => x.ID).FirstOrDefault();
            var   locationID = 1;
            Guest g          = new Guest()
            {
                FirstName   = confirmBooking.firstName,
                LastName    = confirmBooking.lastName,
                Address     = confirmBooking.address,
                PhoneNumber = confirmBooking.phoneno,
                ZipCode     = confirmBooking.zipcode
            };

            RoomReservation confirmRoomReservation = new RoomReservation()
            {
                RoomTypeID        = roomTypeID,
                GuestID           = g.ID,
                checkIn           = confirmBooking.checkinDate,
                checkOut          = confirmBooking.checkoutDate,
                MotelPropertiesID = locationID
            };

            confirmRoomReservation.Guest = g;
            _motelContext.RoomReservations.Add(confirmRoomReservation);


            //_motelContext.Entry(confirmRoomReservation).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _motelContext.SaveChanges();

            ViewData["ReservationID"] = confirmRoomReservation.ID;

            return(View(confirmRoomReservation));
        }
        public async Task <RoomReservation> Create(CreateRoomReservationDto obj)
        {
            RoomReservation roomReservation = _mapper.Map <RoomReservation>(obj);
            await _reservationRepository.Create(roomReservation);

            return(roomReservation);
        }
        public async Task <int> CreatNewReservation(RoomReservation Reservation)
        {
            db.RoomReservationRepo.Create(Reservation);
            int Check = await db.Save();

            return(Check);
        }
        public bool ReserveRoom(RoomReservation roomReservation)
        {
            var data = new RoomReservationData.RoomReservationData();

            data.ReserveRoom(roomReservation);
            return(true);
        }
Example #15
0
        public IHttpActionResult PutRoomReservation(int id, RoomReservation roomReservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roomReservation.Id)
            {
                return(BadRequest());
            }

            db.Entry(roomReservation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomReservationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult Create(int id)
        {
            if (SignInManager.IsSignedIn(User))
            {
                var client = (from clients in _context.Client
                              where clients.Email.Equals(User.Identity.Name)
                              select clients).FirstOrDefault();

                RoomReservation reservation = new RoomReservation();

                reservation.HotelId  = id;
                reservation.ClientId = client.Id;
                _context.Add(reservation);
                _context.SaveChanges();

                var clientReservation = _context.RoomReservation.Include(r => r.Client)
                                        .Include(r => r.Hotel)
                                        .FirstOrDefault(r => r.Id == reservation.Id);
                clientReservation.Hotel.BookedRooms = clientReservation.Hotel.BookedRooms + 1;
                _context.Update(clientReservation);
                _context.SaveChanges();
                return(View(clientReservation));
            }

            return(View());
        }
Example #17
0
 public Form1()
 {
     InitializeComponent();
     roomReservation = new RoomReservation {
         StartTime = DateTime.Now, EndTime = DateTime.Now.AddHours(1)
     };
 }
Example #18
0
        public int UpdateCheckInDateToNow(RoomReservation roomReservation)
        {
            int rowsAffected = 0;

            var conn    = DBConnection.GetDbConnection();
            var cmdText = @"sp_update_checkindate";
            var cmd     = new SqlCommand(cmdText, conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@RoomReservationID", roomReservation.ReservationID);

            try
            {
                conn.Open();

                rowsAffected = cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(rowsAffected);
        }
        public async Task <ActionResult> Delete(int id)
        {
            RoomReservation reservation = await _roomReservationService.GetRoomReservation(id);

            if (reservation != null && !await _roomReservationService.CheckIfDateExpired(reservation.ReservationDate, reservation.TimeId))
            {
                RoomReservation roomReservation = await _roomReservationService.GetAllRoomReservations().Include(m => m.Time).Include(m => m.Member).ThenInclude(u => u.UserRoles).FirstOrDefaultAsync(m => m.Id == id);

                await _roomReservationService.Delete(id);

                await _roomReservationService.CommitAsync();

                if (_configuration.Notify)
                {
                    try
                    {
                        Message message = new Message(
                            _memberService.GetValidMembersEmails(),
                            "Meeting-Room: " + roomReservation.Member.Name + " " + roomReservation.Member.Surname + " rezervasiyasini sildi.",
                            roomReservation.Description + "\n" + roomReservation.ReservationDate + " " + roomReservation.Time.StartTime + "-" + roomReservation.Time.EndTime);
                        await _emailSender.SendEmailAsync(message);
                    }
                    catch
                    {
                    }
                }


                return(Ok());
            }
            return(BadRequest());
        }
        public async Task <IHttpActionResult> AddNewRoomReservation(int idRoom, int idReservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            RoomReservation roomReservation = new RoomReservation();

            roomReservation.Room = await db.Rooms.FindAsync(idRoom);

            if (roomReservation.Room == null)
            {
                return(NotFound());
            }

            roomReservation.Reservation = await db.Reservations.FindAsync(idReservation);

            if (roomReservation.Reservation == null)
            {
                return(NotFound());
            }


            db.RoomReservations.Add(roomReservation);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = roomReservation.IdRoomReservation }, roomReservation));
        }
Example #21
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,StartDate,EndDate,RoomId,StudentId")] RoomReservation roomReservation)
        {
            if (id != roomReservation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roomReservation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomReservationExists(roomReservation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomId"]    = new SelectList(_context.Room, "Id", "Id", roomReservation.RoomId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Id", roomReservation.StudentId);
            return(View(roomReservation));
        }
Example #22
0
        public IHttpActionResult PostReservation(RoomReservation reservation)
        {
            lock (lockObj)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                IQueryable <RoomReservation> query = db.Reservations.Where(o => o.RoomId.Equals(reservation.RoomId) && o.Canceled.Equals(false) &&
                                                                           ((reservation.EndDate >= o.StartDate && reservation.EndDate <= o.EndDate) ||
                                                                            (reservation.StartDate >= o.StartDate && reservation.StartDate <= o.EndDate) ||
                                                                            (reservation.StartDate <= o.StartDate && reservation.EndDate >= o.EndDate)));
                if (query.Count() == 0)
                {
                    db.Reservations.Add(reservation);
                    db.SaveChanges();
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            return(CreatedAtRoute("DefaultApi", new { controller = "RoomReservation", id = reservation.RoomId }, reservation));
        }
        public async Task <IActionResult> Create(ReservationViewModel reservationViewModel)
        {
            if (ModelState.IsValid)
            {
                var client      = _context.Client.Find(reservationViewModel.ClientId);
                var reservation = new Reservation()
                {
                    Id       = Guid.NewGuid(),
                    Client   = client,
                    CheckIn  = reservationViewModel.CheckIn,
                    CheckOut = reservationViewModel.CheckOut
                };
                _context.Add(reservation);
                foreach (var roomId in reservationViewModel.RoomIds)
                {
                    var room            = _context.Rooms.Find(roomId);
                    var roomReservation = new RoomReservation();
                    roomReservation.Room        = room;
                    roomReservation.Reservation = reservation;
                    _context.Add(roomReservation);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservationViewModel));
        }
        public ActionResult Create([Bind(Include = "RR_ID,RoomID,UserID,UserName,CheckIn,CheckOut,Bill,BookingStatus,ACheckIn,ACheckOut")] RoomReservation roomReservation)
        {
            //roomReservation.CheckIn = new DateTime(roomReservation.CheckIn.Year, roomReservation.CheckIn.Month, roomReservation.CheckIn.Day);

            if (ModelState.IsValid /*&& isDateValid(roomReservation)*/)
            {
                //var use = db.RoomReservations.ToList().Find(x => x.RR_ID == roomReservation.RR_ID);
                //if(use!=null)
                //{
                //    ModelState.AddModelError("", "Reservation already exists");
                //    ModelState.Clear();
                //    ViewBag.Messageb = "Reservation ID already exists! please try again";
                //}
                //var user = db.RoomReservations.ToList().Find(x => x.CheckIn == roomReservation.CheckIn);
                //if(user!=null)
                //{
                //    ModelState.AddModelError("", "Date is already Booked");
                //    ModelState.Clear();
                //    ViewBag.Messagea="Date is already booked! please try again";
                //}
                //else
                //{
                //    string str = TempData[]
                //}
                //roomReservation.Bill = roomReservation.calcCost();
                roomReservation.BookingStatus = roomReservation.calcStatus();
                db.RoomReservations.Add(roomReservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RoomID   = new SelectList(db.Rooms, "RoomID", "RoomID", roomReservation.RoomID);
            ViewBag.UserName = new SelectList(db.Users, "UserName", "UserName", roomReservation.UserID);
            return(View(roomReservation));
        }
        public PartialViewResult Delete(int Id = 0)
        {
            var rooms = mrc.MeetingRooms;

            ViewBag.MeetingRooms = rooms;
            var roomReservations = mrc.RoomReservations;

            ViewBag.RoomReservations = roomReservations;
            List <ApplicationUser> users = new List <ApplicationUser>();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                users = db.Users.ToList();
            }
            ViewBag.Users   = users;
            ViewBag.message = "Заявка успешно удалена";
            RoomReservation roomReservation = new RoomReservation();

            foreach (var rr in mrc.RoomReservations)
            {
                if (rr.Id == Id)
                {
                    roomReservation = rr;
                    break;
                }
            }
            mrc.RoomReservations.Remove(roomReservation);
            mrc.SaveChanges();
            return(PartialView());
        }
Example #26
0
 public void RoomReservation(RoomReservation roomReservation)
 {
     using (var dbContext = new RoomReservationContext())
     {
         dbContext.RoomReservations.Add(roomReservation);
         dbContext.SaveChanges();
     }
 }
Example #27
0
        /// <summary>
        /// Add a new room reservation
        /// </summary>
        /// <param name="dateOfStart">The date of start</param>
        /// <param name="dateOfEnd">The date of end</param>
        /// <param name="roomId">The Id of a room</param>
        /// <param name="reservationId">The Id of a reservation</param>
        /// <returns>A new room reservation</returns>
        public RoomReservation AddRoomReservation(DateTime dateOfStart, DateTime dateOfEnd, int roomId, int reservationId)
        {
            RoomReservation roomReservation = new RoomReservation(dateOfStart, dateOfEnd, roomId, reservationId);

            context.RoomReservations.Add(roomReservation);
            context.SaveChanges();
            return(roomReservation);
        }
Example #28
0
 public MainWindow()
 {
     InitializeComponent();
     _reservation = new RoomReservation {
         StartTime = DateTime.Now, EndTime = DateTime.Now.AddHours(1)
     };
     this.DataContext = _reservation;
 }
        public ActionResult DeleteConfirmed(int id)
        {
            RoomReservation roomReservation = db.RoomReservations.Find(id);

            db.RoomReservations.Remove(roomReservation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void ReserveRoom(RoomReservation aRoomReservation)
 {
     using (var context = new RoomReservationContext())
     {
         context.RoomReservations.Add(aRoomReservation);
         context.SaveChanges();
     }
 }
 public MainWindow()
 {
   InitializeComponent();
   roomReservation = new RoomReservation
   {
     StartTime = DateTime.Now,
     EndTime = DateTime.Now.AddHours(1)
   };
   this.DataContext = roomReservation;
 }
        public void ReserveRoom(RoomReservation roomReservation)
        {
            using (var data = new RoomReservationContext())
            {
                data.Database.EnsureCreated();

                data.RoomReservations.Add(roomReservation);
                data.SaveChanges();
            }
        }
        public async Task  GetLastReservationofToday()
        {
            List<RoomReservation> list = await Task<List<RoomReservation>>.FromResult(list);
            RoomReservation   roomreservation=new RoomReservation ();
            //Arrange
            _RoomReservationsRepositorMock.Setup(x => x.GetAll()).ReturnsAsync(list);
            _RoomReservationsRepositorMock.Setup (x=>x.GetLastReservationofToday()).ReturnsAsync(roomreservation);
            //Act
            var result = 

            //Assert
            Assert.AreEqual(result.Count, 2);
            Assert.AreEqual("Full Board", result[0].Name);
            Assert.AreEqual("Half Board", result[1].Name);


        }
        public bool ReserveRoom(RoomReservation roomReservation)
        {
            try
            {
                WriteLine($"received room reservation for room {roomReservation.RoomName}");
                var data = new RoomReservationRepository();
                data.ReserveRoom(roomReservation);
            }
            catch (Exception ex)
            {
                WriteLine($"error {ex.Message}");
                RoomReservationFault fault = new RoomReservationFault { Message = ex.Message };
                throw new FaultException<RoomReservationFault>(fault);
            }
            return true;

        }
        public IHttpActionResult PostRoomReservations( RoomReservation RoomReservation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

          RoomReservation=  _RoomReservationsService.Create(RoomReservation);
        

            return CreatedAtRoute("DefaultApi", new { id = RoomReservation.Id }, RoomReservation);
        }
        /// <summary>
        ///  Add/Edit room reservation 
        /// </summary>
        /// <param name="roomReservation"></param>
        /// <returns></returns>
          private async Task<long> Create_Or_Update_RoomReservation(RoomReservation roomReservation )
          {
              if (roomReservation.BookingForId == (int)RoomReservationSystem.Model.Enums.BookingFor.Member)
                  roomReservation.SponsorTypeId = (int)RoomReservationSystem.Model.Enums.SponsorType.noType;


              if (roomReservation.Id > 0)
                  _RoomReservationRepository.Update(roomReservation, roomReservation.Id.ToString ());
              else
              {
                   roomReservation.ReservationNumber =await GenerateRegistrationNumber();
                   roomReservation = await _RoomReservationRepository.Create(roomReservation);
              }


              return roomReservation.Id;
          }
        public IHttpActionResult PutRoomReservations(long id, RoomReservation  RoomReservation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != RoomReservation.Id)
            {
                return BadRequest();
            }

            

            try
            {
                _RoomReservationsService.Update(RoomReservation);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_RoomReservationsService.Exists(id) )
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }