Esempio n. 1
0
        private void ProcessEventCatering(EventCateringModel cateringModel)
        {
            _isEditMode = (cateringModel != null);

            EventCatering = cateringModel ?? GetEventCatering();
            if (_isEditMode)
            {
                CreateClockItems();
                EventCateringOriginal = EventCatering.Clone();
            }
            EventCatering.PropertyChanged += OnEventBookedProductModelPropertyChanged;
            if (_isEditMode)
            {
                cateringModel.EventBookedProducts.ForEach(product =>
                {
                    product.PropertyChanged += OnEditBookedProductModelPropertyChanged;
                });
            }
        }
Esempio n. 2
0
        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");
            }
        }