async Task registerTime() { var baseDate = AtDate == DateTime.MinValue ? CurrentDate : AtDate; var param = new ModalParameters(); var tb = new TimeBooking { BookingTime = baseDate.Date.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute) }; param.Add(nameof(BookTime.Booking2Change), tb); var ret = Modal.Show <BookTime>("Zeit buchen", param); var result = await ret.Result; if (!result.Cancelled) { var changed = (TimeBooking)result.Data; //Context.TimeBookings?.Add(changed); //await Context.SaveChangesAsync(); await BookingsService.AddBookingAsync(changed); await AppState.RegisteredAsync(changed); StateHasChanged(); } }
private void GolfClock_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var checkDate = ViewModel.SelectedDate; var time = e.AddedItems[0].ToString(); int hours = Convert.ToInt32(time.Substring(0, 2)); int minutes = Convert.ToInt32(time.Substring(3, 2)); var dateTime = new DateTime(checkDate.Year, checkDate.Month, checkDate.Day, hours, minutes, 0); var roomName = (string)(sender as RadClock).Header; var bookingsService = new BookingsService() { BookedRooms = ViewModel.RoomBookings, BookedCaterings = ViewModel.CateringsBookings, BookedGolfs = ViewModel.GolfBookings }; var _event = bookingsService.GetModelByGolf(roomName, dateTime); if (_event != null) { this.IsEnabled = false; var view = new EventDetailsView(new EventModel(_event)); view.ShowDialog(); this.IsEnabled = true; // ViewModel.Refresh(); } }
public HttpResponseMessage EditExistingBooking(int existingBookingId, Booking editBooking, bool?recurrence = false) { BookingsService bookingService = new BookingsService(_logger, _bookingsRepository, _roomsRepository, _locationsRepository, _directoryService); //Find Existing Booking Booking existingBooking = _bookingsRepository.GetById(existingBookingId); try { User currentUser = _directoryService.GetCurrentUser(User.Identity.Name); if (currentUser == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "User not found in Active Directory. " + User.Identity.Name)); } bookingService.EditExistingBooking(existingBooking, editBooking, recurrence, currentUser, ConfigurationManager.AppSettings); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (UnableToEditBookingException e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occured whilst updating the booking(s). Please try again or contact Service Desk")); } catch (DAL.BookingConflictException ex) { _logger.FatalException("Unable to edit booking: " + editBooking.Owner + "/ id: " + editBooking.ID, ex); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message)); } catch (Exception ex) { _logger.FatalException("Unable to edit booking: " + editBooking.Owner + "/ id: " + editBooking.ID, ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public void BaseSetup() { this.repository = new Mock <IFlightBookingsRepository>(); var mapper = CreateMapper(); this.service = new BookingsService(repository.Object, mapper); }
public HttpResponseMessage DeleteBookingById(int bookingId, bool?recurrence = false) { try { BookingsService bookingService = new BookingsService(_logger, _bookingsRepository, _roomsRepository, _locationsRepository, _directoryService); Booking booking = _bookingsRepository.GetById(bookingId); User currentUser = _directoryService.GetCurrentUser(User.Identity.Name); if (currentUser == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "User not found in Active Directory. " + User.Identity.Name)); } bookingService.DeleteExistingBooking(booking, recurrence, currentUser, ConfigurationManager.AppSettings); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (DeletionException e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unable to delete existing booking. An error occured, please contact help desk.")); } catch (Exception ex) { _logger.FatalException("Unable to delete booking: " + bookingId, ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public void BeforeEach() { fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize <BookingStatus>(c => c .Without(x => x.Bookings)); fixture.Customize <Lodgment>(c => c.Without(s => s.Spot) .Without(y => y.Bookings) .Without(y => y.Reviews)); moqRepository = new Mock <IBookingsRepository>(MockBehavior.Strict); moqLodgmentCalculator = new Mock <ILodgmentCalculator>(MockBehavior.Strict); service = new BookingsService(moqRepository.Object, moqLodgmentCalculator.Object); expectedLodgment = fixture.Create <Lodgment>(); lodgment = fixture.Create <Lodgment>(); expectedBooking = fixture.Create <Booking>(); expectedBooking.Lodgment.IsActive = true; bookingConfirmationModel = fixture.Create <BookingConfirmationModel>(); bookingId = fixture.Create <int>(); bookingConfirmationCode = fixture.Create <string>(); bookingStatus = fixture.Create <BookingStatus>(); expectedBookingStatus = fixture.Create <BookingStatus>(); expectedPrice = fixture.Create <double>(); expectedBookings = fixture.CreateMany <Booking>(); paging = fixture.Create <PagingModel>(); paginatedBookings = fixture.Create <PaginatedModel <Booking> >(); }
public List <BookHost> GetBookings(string value) { var service = new BookingsService(); var listBookings = service.Get_bookings_current_host(Convert.ToInt32(value)); return(listBookings); }
public void MethodGetAllOfRestaurantShould_CallRepositoryMethodAll() { var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); var restaurantId = Guid.NewGuid(); service.GetAllOfRestaurant(restaurantId); repositoryMock.Verify(r => r.All, Times.Once); }
public void MethodGetByIdShould_CallRepositoryMethodGetById() { var id = Guid.NewGuid(); var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); service.GetById(id); repositoryMock.Verify(r => r.GetById(id)); }
public void GetBookingById_ThrowsEntityNotFound_WhenBookingDoesNotExist() { var nonExistingId = Guid.NewGuid(); var bookingService = new BookingsService(bookingRepoMock.Object); Assert.ThrowsException <EntityNotFoundException>(() => { bookingService.GetBookingById(nonExistingId.ToString()); }); }
public void GetBookingById_ThrowsException_WhenBookingIdHasInvalidValue() { var bookingService = new BookingsService(bookingRepoMock.Object); var badId = "asdjlkasdklas sakld askld"; Assert.ThrowsException <Exception>(() => { bookingService.GetBookingById(badId); }); }
private async Task loadData() { var baseDate = AtDate == DateTime.MinValue ? TheDate : AtDate; Bookings = await BookingsService.GetBookingsForDayAsync(baseDate); //Bookings = await Context.TimeBookings // .Where(x => x.BookingTime > baseDate.Date && x.BookingTime <= baseDate.Date.AddDays(1)) // .OrderBy(x => x.BookingTime) // .ToListAsync(); }
public BookingsController( CustomerRepository customerRepository, CustomerService customerService, BookingRepository bookingRepository, BookingsService bookingsService) { _customerRepository = customerRepository; _customerService = customerService; _bookingRepository = bookingRepository; _bookingsService = bookingsService; }
public RestfulBookerClient(string username, string password, string baseUrl = "https://restful-booker.herokuapp.com") { var client = new RestClient(baseUrl) { Authenticator = new HttpBasicAuthenticator(username, password) }; client.UseSerializer(() => new JsonNetSerializer()); client.AddDefaultHeader("Accept", "application/json"); Bookings = new BookingsService(client); Rooms = new RoomsService(client); }
public BookingsController(IBookingRepository bookingRepository, ILocationRepository locationRepository, IRoomRepository roomsRepository, IDirectoryService directoryService, EmailHelper helper) { _logger = NLog.LogManager.GetCurrentClassLogger(); _directoryService = directoryService; _bookingService = new BookingsService(bookingRepository, roomsRepository, locationRepository, directoryService, helper); _bookingsRepository = bookingRepository; _locationsRepository = locationRepository; _roomsRepository = roomsRepository; _logger.Trace(LoggerHelper.InitializeClassMessage()); }
public void MethodCreateShould_CallFactoryMethodCreateBooking(int peopleCount) { var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); var restaurantId = Guid.NewGuid(); var userId = Guid.NewGuid(); var dateTime = DateTime.Now; service.Create(restaurantId, userId, dateTime, peopleCount); factoryMock.Verify(f => f.Create(restaurantId, userId, dateTime, peopleCount)); }
public void MethodDeleteShould_CallUnitOfWorkMethodCommit() { var booking = new Booking() { Id = Guid.NewGuid() }; var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); service.Delete(booking); unitOfWorkMock.Verify(r => r.Commit(), Times.Once); }
public void MethodGetByIdShould_ReturnCorrectValue() { var id = Guid.NewGuid(); var booking = new Booking() { Id = id }; repositoryMock.Setup(r => r.GetById(id)).Returns(booking); var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); var result = service.GetById(id); Assert.AreSame(booking, result); }
//protected override async Task OnInitializedAsync() //{ // await loadData(); //} public async Task Edit(TimeBooking bTime) { var param = new ModalParameters(); param.Add(nameof(BookTime.Booking2Change), bTime); var ret = Modal.Show <BookTime>("Zeit ändern", param); var result = await ret.Result; if (!result.Cancelled) { var changed = (TimeBooking)result.Data; //Context.Update(changed); //await Context.SaveChangesAsync(); await BookingsService.UpdateBookingAsync(changed); await AppState.RegisteredAsync(changed); } }
public void GetBookingById_Returns_BookingWhenExists() { Exception throwException = null; var bookingService = new BookingsService(bookingRepoMock.Object); Booking booking = null; try { booking = bookingService.GetBookingById(existingBookingId.ToString()); } catch (Exception e) { throwException = e; } Assert.IsNull(throwException, $"Exception was thrown"); Assert.IsNotNull(booking); }
public async Task Delete(TimeBooking bTime) { var param = new ModalParameters(); param.Add(nameof(Confirm.Message), "Wollen Sie diesen Zeitpunkt wirklich löschen?"); param.Add(nameof(Confirm.OkButtonText), "Löschen"); var ret = Modal.Show <Confirm>("Wirklich löschen", param); var result = await ret.Result; if (!result.Cancelled) { if ((bool)result.Data == true) { await BookingsService.DeleteBookingAsync(bTime); await AppState.RegisteredAsync(bTime); } } }
private void RoomClock_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var checkDate = ViewModel.SelectedDate; var time = e.AddedItems[0].ToString(); int hours = Convert.ToInt32(time.Substring(0, 2)); int minutes = Convert.ToInt32(time.Substring(3, 2)); var dateTime = new DateTime(checkDate.Year, checkDate.Month, checkDate.Day, hours, minutes, 0); var roomName = (string)(sender as RadClock).Header; var bookingsService = new BookingsService() { BookedRooms = ViewModel.RoomBookings, BookedCaterings = ViewModel.CateringsBookings, BookedGolfs = ViewModel.GolfBookings }; var events = bookingsService.GetModelsByRoom(roomName, dateTime).Distinct().ToList(); if (events.Any()) { this.IsEnabled = false; // TODO: If current date has several events ? //Done if (events.Count == 1) { var view = new EventDetailsView(new EventModel(events.First())); view.ShowDialog(); } else { var view = new EventsBookedView(new ObservableCollection <EventModel>(events.Select(p => new EventModel(p)))); view.ShowDialog(); } this.IsEnabled = true; //ViewModel.Refresh(); } }
public void MethodGetAllOfRestaurantShould_ReturnCorrectResult() { var restaurantId = Guid.NewGuid(); var booking = new Booking() { RestaurantId = restaurantId }; var list = new List <Booking>() { booking }; repositoryMock.Setup(r => r.All).Returns(list.AsQueryable()); var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); var result = service.GetAllOfRestaurant(restaurantId); Assert.AreSame(booking, result.ToList().First()); }
public BookingsServiceTests() { var options = new DbContextOptionsBuilder <TrainConnectedDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new TrainConnectedDbContext(options); AutoMapperConfig.RegisterMappings(new[] { typeof(ErrorViewModel).GetTypeInfo().Assembly, typeof(WorkoutActivityEditInputModel).GetTypeInfo().Assembly, }); this.workoutsRepository = new EfRepository <Workout>(dbContext); this.usersRepository = new EfRepository <TrainConnectedUser>(dbContext); this.bookingsRepository = new EfRepository <Booking>(dbContext); this.trainConnectedUsersWorkoutsRepository = new EfRepository <TrainConnectedUsersWorkouts>(dbContext); this.paymentMethodsRepository = new EfRepository <PaymentMethod>(dbContext); this.bookingsService = new BookingsService(this.workoutsRepository, this.usersRepository, this.bookingsRepository, this.trainConnectedUsersWorkoutsRepository, this.paymentMethodsRepository); }
public HttpResponseMessage SaveNewBooking(Booking newBooking) { BookingsService bookingService = new BookingsService(_logger, _bookingsRepository, _roomsRepository, _locationsRepository, _directoryService); try { User currentUser = _directoryService.GetCurrentUser(User.Identity.Name); if (currentUser == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "User not found in Active Directory. " + User.Identity.Name)); } bookingService.SaveNewBooking(newBooking, currentUser, ConfigurationManager.AppSettings); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (BookingsService.BookingConflictException e) { var clashedBookingsString = new JavaScriptSerializer().Serialize(ConvertBookingsToDTOs(e.clashedBookings)); return(Request.CreateErrorResponse(HttpStatusCode.Conflict, clashedBookingsString)); } catch (DAL.BookingConflictException e) { _logger.FatalException("Unable to save new booking: " + newBooking.Owner + "/" + newBooking.StartDate, e); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, e.Message)); } catch (ClashedBookingsException e) { var clashedBookingsString = new JavaScriptSerializer().Serialize(ConvertBookingsToDTOs(e.clashedBookings)); return(Request.CreateErrorResponse(HttpStatusCode.BadGateway, clashedBookingsString)); } catch (UnauthorisedOverwriteException e) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Unauthorised to overwrite bookings.")); } catch (Exception e) { _logger.FatalException("Unable to save new booking: " + newBooking.Owner + "/" + newBooking.StartDate, e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public void MethodCreateShould_CallRepositoryMethodAdd(int peopleCount) { var service = new BookingsService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object, restaurantsServiceMock.Object); var restaurantId = Guid.NewGuid(); var userId = Guid.NewGuid(); var dateTime = DateTime.Now; var booking = new Booking() { RestaurantId = restaurantId, UserId = userId, DateTime = dateTime, PeopleCount = peopleCount }; factoryMock.Setup(f => f.Create(restaurantId, userId, dateTime, peopleCount)) .Returns(booking); service.Create(restaurantId, userId, dateTime, peopleCount); repositoryMock.Verify(r => r.Add(booking), Times.Once); }
private async void SubmitCommandExecuted() { IsBusy = true; SubmitCommand.RaiseCanExecuteChanged(); if (EventGolf.HasErrors) { IsBusy = false; SubmitCommand.RaiseCanExecuteChanged(); return; } EventGolf.EventGolf.Event = _event.Event; var eventGolf = EventGolf.Clone(); EventGolfModel linkedEventGolf = GetEventGolf(); EventGolf linkedGolf = null; _eventDataUnit.EventGolfsRepository.Refresh(RefreshMode.ClientWins); var golfs = await _eventDataUnit.EventGolfsRepository.GetAllAsync(); golfs = _eventDataUnit.EventGolfsRepository.SetGolfCurrentValues(golfs).ToList(); var eventGolfs = golfs.Select(x => new EventGolfModel(x)).ToList(); if (_isEditMode) { if (EventGolf.EventGolf.LinkedEventGolfId != null) { linkedGolf = eventGolfs.FirstOrDefault(p => p.EventGolf.ID == EventGolf.EventGolf.LinkedEventGolfId).EventGolf; eventGolfs.RemoveAll(x => x.EventGolf.ID == EventGolf.EventGolf.LinkedEventGolfId); } } eventGolfs.RemoveAll(x => x.EventGolf.ID == _eventGolf.EventGolf.ID); if (AlreadyBookedGolfs != null) { AlreadyBookedGolfs.ForEach(alreadyBookedItem => { eventGolfs.RemoveAll(p => p.EventGolf.ID == alreadyBookedItem.EventGolf.ID); if (alreadyBookedItem.EventGolf.EventGolf1 != null) { eventGolfs.RemoveAll(p => p.EventGolf.ID == alreadyBookedItem.EventGolf.EventGolf1.ID); } }); } var bookingService = new BookingsService { BookedGolfs = eventGolfs }; MapChangedDataAfterRefresh(EventGolf.EventGolf, eventGolf.EventGolf); //check 1st Golf Booking var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, _eventGolf.Time.Hour, _eventGolf.Time.Minute, 0); var endTime = startTime.AddMinutes(EventGolf.Golf.TimeInterval.TotalMinutes * EventGolf.EventGolf.Slots); var firstBookingAllowed = bookingService.IsGolfAvailable(EventGolf.Golf, startTime, endTime); var linkedBookingAllowed = false; var bookingAllowed = false; //Check if first booking allowed and then check second if allowed if (firstBookingAllowed) { //Check Whether Golf is 9 golfHoles or 18 Holes if (EventGolf.GolfHole.Hole.ToLower() == "18 holes") { if (EventGolf.Golf.TurnDefault != null) { var golf = Golfs.FirstOrDefault(m => m.ID == EventGolf.Golf.TurnDefault); if (golf != null) { startTime = startTime.Add(EventGolf.Golf.TurnTime); startTime = startTime.AddMinutes(((new TimeSpan(startTime.Hour, startTime.Minute, 0).TotalMinutes - golf.StartTime.TotalMinutes) % golf.TimeInterval.TotalMinutes)); // startTime = startTime.AddTicks((golf.StartTime.Ticks + new TimeSpan(0, 0, 1).Ticks - new TimeSpan(startTime.Hour, startTime.Minute, startTime.Second).Ticks) / golf.TimeInterval.Ticks); endTime = startTime.AddMinutes(Golfs.FirstOrDefault(m => m.ID == EventGolf.Golf.TurnDefault).TimeInterval.TotalMinutes *EventGolf.EventGolf.Slots); MapChangedDataAfterRefresh(linkedEventGolf.EventGolf, eventGolf.EventGolf); linkedEventGolf.EventGolf.TeeID = golf.ID; linkedEventGolf.EventGolf.Time = new DateTime(0001, 01, 01, startTime.Hour, startTime.Minute, startTime.Second); linkedEventGolf.EventGolf.IsLinked = true; linkedEventGolf.EventGolf.Event = _event.Event; linkedBookingAllowed = bookingService.IsGolfAvailable(golf, startTime, endTime); } } else { EventGolf.EventGolf.LinkedEventGolfId = null; linkedBookingAllowed = true; } bookingAllowed = firstBookingAllowed && linkedBookingAllowed; } else { bookingAllowed = firstBookingAllowed; } } else { bookingAllowed = firstBookingAllowed; } if (bookingAllowed && EventGolf.HasValidProducts) { if (!_isEditMode) { if (EventGolf.GolfHole.Hole.ToLower() == "18 holes" && EventGolf.Golf.TurnDefault != null && Golfs.FirstOrDefault(m => m.ID == EventGolf.Golf.TurnDefault) != null) { EventGolf.EventGolf.EventGolf1 = linkedEventGolf.EventGolf; EventGolf.EventGolf.LinkedEventGolfId = linkedEventGolf.EventGolf.ID; } _event.EventGolfs.Add(EventGolf); _eventDataUnit.EventGolfsRepository.Add(EventGolf.EventGolf); //if (EventGolf.GolfHole.Hole.ToLower() == "18 holes") // _eventDataUnit.EventGolfsRepository.Add(linkedEventGolf.EventGolf); foreach (var product in EventGolf.EventBookedProducts) { product.EventCharge.EventCharge.ShowInInvoice = EventGolf.EventGolf.ShowInInvoice; _event.EventCharges.Add(product.EventCharge); _eventDataUnit.EventChargesRepository.Add(product.EventCharge.EventCharge); _event.EventBookedProducts.Add(product); _eventDataUnit.EventBookedProductsRepository.Add(product.EventBookedProduct); } } else { if (linkedGolf != null) { _eventDataUnit.EventGolfsRepository.Delete(linkedGolf); } if (EventGolf.GolfHole.Hole.ToLower() == "18 holes" && EventGolf.Golf.TurnDefault != null && Golfs.FirstOrDefault(m => m.ID == EventGolf.Golf.TurnDefault) != null) { EventGolf.EventGolf.EventGolf1 = linkedEventGolf.EventGolf; EventGolf.EventGolf.LinkedEventGolfId = linkedEventGolf.EventGolf.ID; } //if (EventGolf.GolfHole.Hole.ToLower() == "18 holes") // _eventDataUnit.EventGolfsRepository.Add(linkedEventGolf.EventGolf); EventGolf.EventBookedProducts.ForEach(eventBookedProduct => { eventBookedProduct.EventCharge.EventCharge.ShowInInvoice = EventGolf.EventGolf.ShowInInvoice; }); var newProdcuts = _eventGolf.EventBookedProducts.Except(_event.EventBookedProducts).ToList(); if (newProdcuts.Any()) { foreach (var prodcut in newProdcuts) { _event.EventBookedProducts.Add(prodcut); _eventDataUnit.EventBookedProductsRepository.Add(prodcut.EventBookedProduct); _event.EventCharges.Add(prodcut.EventCharge); _eventDataUnit.EventChargesRepository.Add(prodcut.EventCharge.EventCharge); } } } RaisePropertyChanged("CloseDialog"); } else { IsBusy = false; SubmitCommand.RaiseCanExecuteChanged(); RaisePropertyChanged("DisableParentWindow"); string confirmText = Resources.MESSAGE_TEE_IS_BOOKED; RadWindow.Alert(new DialogParameters() { Owner = Application.Current.MainWindow, Content = confirmText, }); RaisePropertyChanged("EnableParentWindow"); } }
private async void SubmitCommandExecuted() { SetLoadingIndicator(true); if (EventCatering.HasErrors) { SetLoadingIndicator(false); return; } EventCatering.EventCatering.Event = _event.Event; var eventCatering = EventCatering.Clone(); _eventDataUnit.EventRoomsRepository.Refresh(RefreshMode.ClientWins); var rooms = await _eventDataUnit.EventRoomsRepository.GetAllAsync(eRoom => !eRoom.Event.IsDeleted && eRoom.EventID != _event.Event.ID && eRoom.Event.Date == _event.Event.Date && eRoom.RoomID == EventCatering.Room.ID); rooms = _eventDataUnit.EventRoomsRepository.SetRoomsCurrentValues(rooms).ToList(); var eventRooms = rooms.Select(x => new EventRoomModel(x)).ToList(); if (AlreadyBookedRooms != null) { AlreadyBookedRooms.ForEach(alreadyBookedItem => { eventRooms.RemoveAll(p => p.EventRoom.ID == alreadyBookedItem.EventRoom.ID); }); } _eventDataUnit.EventCateringsRepository.Refresh(RefreshMode.ClientWins); var caterings = await _eventDataUnit.EventCateringsRepository.GetAllAsync(eCatering => !eCatering.Event.IsDeleted && eCatering.EventID != _event.Event.ID && eCatering.Event.Date == _event.Event.Date && eCatering.RoomID == EventCatering.Room.ID ); caterings = _eventDataUnit.EventCateringsRepository.SetCateringsCurrentValues(caterings).ToList(); var eventCaterings = caterings.Select(x => new EventCateringModel(x)).ToList(); if (AlreadyBookedCaterings != null) { AlreadyBookedCaterings.ForEach(alreadyBookedItem => eventCaterings.RemoveAll(p => p.EventCatering.ID == alreadyBookedItem.EventCatering.ID)); } eventCaterings.RemoveAll(x => x.EventCatering.ID == _eventCatering.EventCatering.ID); var bookingService = new BookingsService { BookedRooms = eventRooms, BookedCaterings = eventCaterings }; MapChangedDataAfterRefresh(EventCatering.EventCatering, eventCatering.EventCatering); var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, _eventCatering.StartTime.Hour, _eventCatering.StartTime.Minute, 0); var endTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, _eventCatering.EndTime.Hour, _eventCatering.EndTime.Minute, 0); bool bookingAllowed = bookingService.IsRoomAvailable(_event.Event.ID, EventCatering.Room, startTime, endTime); if (!bookingAllowed && EventCatering.Room.MultipleBooking) { bool? dialogResult = null; string confirmText = Resources.MESSAGE_ROOM_IS_BOOKED_BUT_SOPPORTS_MULTIBOOKING; RadWindow.Confirm(new System.Windows.Controls.TextBlock { Text = confirmText, TextWrapping = TextWrapping.Wrap, Width = 400 }, (s, args) => { dialogResult = args.DialogResult; }); if (dialogResult != true) { SetLoadingIndicator(false); return; } bookingAllowed = true; } if (bookingAllowed && EventCatering.HasValidProducts) { if (!_isEditMode) { _event.EventCaterings.Add(EventCatering); _eventDataUnit.EventCateringsRepository.Add(EventCatering.EventCatering); foreach (var product in EventCatering.EventBookedProducts) { product.EventCharge.EventCharge.ShowInInvoice = EventCatering.EventCatering.ShowInInvoice; _event.EventCharges.Add(product.EventCharge); _eventDataUnit.EventChargesRepository.Add(product.EventCharge.EventCharge); _event.EventBookedProducts.Add(product); _eventDataUnit.EventBookedProductsRepository.Add(product.EventBookedProduct); } } else { EventCatering.EventBookedProducts.ForEach(eventBookedProduct => { eventBookedProduct.EventCharge.EventCharge.ShowInInvoice = EventCatering.EventCatering.ShowInInvoice; }); var newProdcuts = _eventCatering.EventBookedProducts.Except(_event.EventBookedProducts).ToList(); if (newProdcuts.Any()) { foreach (var product in newProdcuts) { _event.EventBookedProducts.Add(product); _eventDataUnit.EventBookedProductsRepository.Add(product.EventBookedProduct); _event.EventCharges.Add(product.EventCharge); _eventDataUnit.EventChargesRepository.Add(product.EventCharge.EventCharge); } } } RaisePropertyChanged("CloseDialog"); } else { RaisePropertyChanged("DisableParentWindow"); string confirmText = Resources.MESSAGE_ROOM_IS_BOOKED; RadWindow.Alert(new DialogParameters { Owner = Application.Current.MainWindow, Content = confirmText, }); SetLoadingIndicator(false); RaisePropertyChanged("EnableParentWindow"); } }
private void CheckRoomBookings() { if (BookingsCalendar.SelectedDate == null) { return; } var checkDate = ViewModel.SelectedDate; var displayRooms = RoomItemsControl.ChildrenOfType <RadClock>().ToList(); var bookingsService = new BookingsService() { BookedRooms = ViewModel.RoomBookings, BookedCaterings = ViewModel.CateringsBookings }; if (bookingsService.BookedRooms.Count != 0 || bookingsService.BookedCaterings.Count != 0) { foreach (var room in ViewModel.Rooms) { Dispatcher.BeginInvoke((Action)(() => { var displayRoom = displayRooms.FirstOrDefault(x => (string)x.Header == room.Name); var roomTimeValues = displayRoom.ChildrenOfType <TextBlock>().ToList(); roomTimeValues.RemoveAt(0); // delete header TextBlock foreach (TextBlock roomTimeValue in roomTimeValues) { int hours = Convert.ToInt32(roomTimeValue.Text.Substring(0, 2)); int minutes = Convert.ToInt32(roomTimeValue.Text.Substring(3, 2)); var value = new DateTime(checkDate.Year, checkDate.Month, checkDate.Day, hours, minutes, 0); if (room.Room.EndTime < room.Room.StartTime) { if ((new TimeSpan(hours, minutes, 0)).Ticks < (new TimeSpan(room.Room.EndTime.Hours, room.Room.EndTime.Minutes, room.Room.EndTime.Seconds)).Ticks) { value = value.AddDays(1); } } var isAvailable = bookingsService.IsRoomAvailable(room.Room, value); if (isAvailable) { roomTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); roomTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#111111")); } else { roomTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#2980b9")); roomTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); } } })); } } else { foreach (var room in ViewModel.Rooms) { Dispatcher.BeginInvoke((Action)(() => { var displayRoom = displayRooms.FirstOrDefault(x => (string)x.Header == room.Name); var roomTimeValues = displayRoom.ChildrenOfType <TextBlock>().ToList(); roomTimeValues.RemoveAt(0); // delete header TextBlock foreach (TextBlock roomTimeValue in roomTimeValues) { roomTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); roomTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#111111")); } })); } } }
private void CheckGolfBookings() { if (BookingsCalendar.SelectedDate == null) { return; } var checkDate = ViewModel.SelectedDate; var displayGolfs = GolfItemsControl.ChildrenOfType <RadClock>().ToList(); var bookingsService = new BookingsService() { BookedGolfs = ViewModel.GolfBookings }; if (bookingsService.BookedGolfs.Count != 0) { foreach (var golf in ViewModel.Golfs) { Dispatcher.BeginInvoke((Action)(() => { var displayGolf = displayGolfs.FirstOrDefault(x => (string)x.Header == golf.Name); var golfTimeValues = displayGolf.ChildrenOfType <TextBlock>().ToList(); golfTimeValues.RemoveAt(0); // delete header TextBlock foreach (TextBlock golfTimeValue in golfTimeValues) { int hours = Convert.ToInt32(golfTimeValue.Text.Substring(0, 2)); int minutes = Convert.ToInt32(golfTimeValue.Text.Substring(3, 2)); var startTime = new DateTime(checkDate.Year, checkDate.Month, checkDate.Day, hours, minutes, 0); var isAvailable = bookingsService.IsGolfAvailable(golf.Golf, startTime); if (isAvailable) { golfTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); golfTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#111111")); } else { golfTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#2980b9")); golfTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); } } })); } } else { foreach (var golf in ViewModel.Golfs) { Dispatcher.BeginInvoke((Action)(() => { var displayGolf = displayGolfs.FirstOrDefault(x => (string)x.Header == golf.Name); var golfTimeValues = displayGolf.ChildrenOfType <TextBlock>().ToList(); golfTimeValues.RemoveAt(0); // delete header TextBlock foreach (TextBlock golfTimeValue in golfTimeValues) { golfTimeValue.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff")); golfTimeValue.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#111111")); } })); } } }