private void ProcessEventRoom(EventRoomModel roomModel) { _isEditMode = (roomModel != null); EventRoom = (_isEditMode) ? roomModel : GetEventRoom(); if (_isEditMode) { CreateClockItems(); EventRoomOriginal = EventRoom.Clone(); } EventRoom.PropertyChanged += OnEventBookedProductModelPropertyChanged; }
private async void SubmitCommandExecuted() { SetLoadingIndicator(true); if (EventRoom.HasErrors) { SetLoadingIndicator(false); return; } var eventRoom = EventRoom.Clone(); EventRoom.EventRoom.Event = _event.Event; _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 == EventRoom.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); }); } eventRooms.RemoveAll(x => x.EventRoom.ID == _eventRoom.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 == EventRoom.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); }); } var bookingService = new BookingsService { BookedRooms = eventRooms, BookedCaterings = eventCaterings }; MapChangedDataAfterRefresh(EventRoom.EventRoom, eventRoom.EventRoom); var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, _eventRoom.StartTime.Hour, _eventRoom.StartTime.Minute, 0); var endTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, _eventRoom.EndTime.Hour, _eventRoom.EndTime.Minute, 0); bool bookingAllowed = bookingService.IsRoomAvailable(_event.Event.ID, EventRoom.Room, startTime, endTime); if (!bookingAllowed && EventRoom.Room.MultipleBooking) { bool? dialogResult = null; string confirmText = Resources.MESSAGE_ROOM_IS_BOOKED_BUT_SOPPORTS_MULTIBOOKING; RadWindow.Confirm(new DialogParameters { Owner = Application.Current.MainWindow, Content = confirmText, Closed = (sender, args) => { dialogResult = args.DialogResult; } }); if (dialogResult != true) { SetLoadingIndicator(false); return; } bookingAllowed = true; } if (bookingAllowed && EventRoom.HasValidProducts) { if (!_isEditMode) { _event.EventRooms.Add(EventRoom); _eventDataUnit.EventRoomsRepository.Add(EventRoom.EventRoom); foreach (var product in EventRoom.EventBookedProducts) { product.EventCharge.EventCharge.ShowInInvoice = EventRoom.EventRoom.ShowInInvoice; _event.EventCharges.Add(product.EventCharge); _eventDataUnit.EventChargesRepository.Add(product.EventCharge.EventCharge); _event.EventBookedProducts.Add(product); _eventDataUnit.EventBookedProductsRepository.Add(product.EventBookedProduct); } } else { EventRoom.EventBookedProducts.ForEach(eventBookedProduct => { eventBookedProduct.EventCharge.EventCharge.ShowInInvoice = EventRoom.EventRoom.ShowInInvoice; }); var newProdcuts = _eventRoom.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 { RaisePropertyChanged("DisableParentWindow"); string confirmText = Resources.MESSAGE_ROOM_IS_BOOKED; RadWindow.Alert(new DialogParameters { Owner = Application.Current.MainWindow, Content = confirmText, }); SetLoadingIndicator(false); RaisePropertyChanged("EnableParentWindow"); } }