Beispiel #1
0
        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 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");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Double Check whether the resources booked in the event are not booked by someone else meanwhile.
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task ValidateResourcesAvailability()
        {
            AlreadyBookedCaterings  = new List <EventCateringModel>();
            AlreadyBookedRooms      = new List <EventRoomModel>();
            AlreadyBookedGolfs      = new List <EventGolfModel>();
            AlreadyBookedEventItems = new ObservableCollection <EventItemModel>();

            _eventsDataUnit.EventRoomsRepository.Refresh(RefreshMode.ClientWins);
            var rooms = await _eventsDataUnit.EventRoomsRepository.GetAllAsync(p => p.Event.ID != Event.Event.ID);

            var eventRooms = rooms.Select(x => new EventRoomModel(x)).ToList();

            _eventsDataUnit.EventCateringsRepository.Refresh(RefreshMode.ClientWins);
            var caterings = await _eventsDataUnit.EventCateringsRepository.GetAllAsync(p => p.Event.ID != Event.Event.ID);

            var eventCaterings = caterings.Select(x => new EventCateringModel(x)).ToList();

            _eventsDataUnit.EventGolfsRepository.Refresh(RefreshMode.ClientWins);
            var golfs = await _eventsDataUnit.EventGolfsRepository.GetAllAsync(p => p.Event.ID != Event.Event.ID);

            var eventGolfs = golfs.Select(x => new EventGolfModel(x)).ToList();

            var golfBookingService = new BookingsService()
            {
                BookedGolfs = eventGolfs
            };
            var roomBookingService = new BookingsService()
            {
                BookedRooms = eventRooms, BookedCaterings = eventCaterings
            };

            foreach (var eventItem in _event.EventItems)
            {
                if (eventItem.Instance.GetType() == typeof(EventCateringModel))
                {
                    var model = (EventCateringModel)eventItem.Instance;
                    if (!model.EventCatering.Room.MultipleBooking)
                    {
                        var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, model.StartTime.Hour, model.StartTime.Minute, 0);
                        var endTime   = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, model.EndTime.Hour, model.EndTime.Minute, 0);
                        if (roomBookingService.IsRoomAvailable(_event.Event.ID, model.Room, startTime, endTime))
                        {
                            roomBookingService.BookedCaterings.Add(model);
                        }
                        else
                        {
                            AlreadyBookedCaterings.Add(model);
                            AlreadyBookedEventItems.Add(eventItem);
                        }
                    }
                }
                else if (eventItem.Instance.GetType() == typeof(EventRoomModel))
                {
                    var model = (EventRoomModel)eventItem.Instance;
                    if (!model.EventRoom.Room.MultipleBooking)
                    {
                        var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, model.StartTime.Hour, model.StartTime.Minute, 0);
                        var endTime   = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, model.EndTime.Hour, model.EndTime.Minute, 0);
                        if (roomBookingService.IsRoomAvailable(_event.Event.ID, model.Room, startTime, endTime))
                        {
                            roomBookingService.BookedRooms.Add(model);
                        }
                        else
                        {
                            AlreadyBookedRooms.Add(model);
                            AlreadyBookedEventItems.Add(eventItem);
                        }
                    }
                }
                else if (eventItem.Instance.GetType() == typeof(EventGolfModel))
                {
                    var model = (EventGolfModel)eventItem.Instance;

                    var startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, model.Time.Hour, model.Time.Minute, 0);
                    var endTime   = startTime.AddMinutes(model.Golf.TimeInterval.TotalMinutes * model.EventGolf.Slots);
                    if (golfBookingService.IsGolfAvailable(model.Golf, startTime, endTime))
                    {
                        golfBookingService.BookedGolfs.Add(model);
                        if (model.EventGolf.EventGolf1 != null)
                        {
                            var linkedGolf = new EventGolfModel(model.EventGolf.EventGolf1);
                            startTime = new DateTime(_event.Date.Year, _event.Date.Month, _event.Date.Day, linkedGolf.Time.Hour, linkedGolf.Time.Minute, 0);
                            endTime   = startTime.AddMinutes(linkedGolf.Golf.TimeInterval.TotalMinutes * linkedGolf.EventGolf.Slots);
                            if (golfBookingService.IsGolfAvailable(linkedGolf.Golf, startTime, endTime))
                            {
                                golfBookingService.BookedGolfs.Add(linkedGolf);
                            }
                            else
                            {
                                AlreadyBookedGolfs.Add(model);
                                AlreadyBookedEventItems.Add(eventItem);
                            }
                        }
                    }
                    else
                    {
                        AlreadyBookedGolfs.Add(model);
                        AlreadyBookedEventItems.Add(eventItem);
                    }
                }
            }
        }