public ActionResult Edit(Booking booking, int id) { if (booking.CheckIn < DateTime.Today) { ModelState.AddModelError("CheckIn", "Datum mora biti veci od danasnjeg."); } if (booking.CheckOut < booking.CheckIn) { ModelState.AddModelError("CheckOut", "CheckOut mora biti veci od CheckIn-a"); } if (ModelState.IsValid) { _context.Entry(booking).State = EntityState.Modified; _context.SaveChanges(); BookingHub.RefreshBookings(booking); return(RedirectToAction("Index")); } ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId); ViewBag.StayId = new SelectList(_context.Stays, "Id", "StayName", booking.StayId); return(View(booking)); }
public ActionResult DeleteConfirmed(int id) { Booking booking = _context.Bookings.Find(id); _context.Bookings.Remove(booking); _context.SaveChanges(); BookingHub.RefreshBookings(booking); return(RedirectToAction("Index")); }
public ActionResult CreateBooking([Bind(Include = "Id,ConsumerId,StayId,CheckIn,CheckOut")] Booking booking) { var checkIn = _context.Bookings.Any(b => b.CheckIn == booking.CheckIn); var checkOut = _context.Bookings.Any(b => b.CheckOut == booking.CheckOut); var stayDb = _context.Bookings.Any(b => b.StayId == booking.StayId); if (checkIn == true && stayDb == true) { ModelState.AddModelError("CheckIn", "Datum je vec rezervisan"); ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId); ViewBag.StayId = new SelectList(_context.Stays, "Id", "StayName", booking.StayId); return(View(booking)); } if (checkOut == true && stayDb == true) { ModelState.AddModelError("CheckOut", "Datum je vec rezervisan"); ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId); ViewBag.StayId = new SelectList(_context.Stays, "Id", "StayName", booking.StayId); return(View(booking)); } if (booking.CheckIn < DateTime.Today) { ModelState.AddModelError("CheckIn", "Datum mora biti veci od danasnjeg."); } if (booking.CheckOut < booking.CheckIn) { ModelState.AddModelError("CheckOut", "CheckOut mora biti veci od CheckIn-a"); } if (ModelState.IsValid) { _context.Bookings.Add(booking); _context.SaveChanges(); BookingHub.RefreshBookings(booking); return(RedirectToAction("Index")); } ViewBag.ConsumerId = new SelectList(_context.Consumers, "Id", "Name", booking.ConsumerId); ViewBag.StayId = new SelectList(_context.Stays, "Id", "StayName", booking.StayId); return(View(booking)); }
public async Task HubClientsCalledWithBookingPositons(int bookingSeatCount) { // arrange Mock <IHubCallerClients <IBookingHub> > mockClients = new Mock <IHubCallerClients <IBookingHub> >(); Mock <IBookingHub> mockClientProxy = new Mock <IBookingHub>(); mockClients.Setup(clients => clients.All).Returns(mockClientProxy.Object); BookingHub bookingHub = new BookingHub() { Clients = mockClients.Object }; var bookingDto = new BookingDTO { Date = DateTime.Now, Id = Guid.NewGuid().ToString(), Email = "", Positions = new List <ServicePlacePositionDTO>() }; for (int i = 0; i < bookingSeatCount; i++) { bookingDto.Positions.Add(new ServicePlacePositionDTO { }); } // act await bookingHub.SendBooking(bookingDto); // assert mockClients.Verify(clients => clients.All, Times.Once); mockClientProxy.Verify( clientProxy => clientProxy.RecieveNewBooking( It.Is <BookingDTO>(x => x.Email == "" && x.Positions.Count == bookingSeatCount) ), Times.Once); }