Ejemplo n.º 1
0
        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"));
                         }
                     }));
                }
            }
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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");
            }
        }