private void EditItemCommandExecuted(EventItemModel item) { RaisePropertyChanged("DisableParentWindow"); if (item.Instance.GetType() == typeof(EventCateringModel)) { var model = (EventCateringModel)item.Instance; var window = new AddCateringItemView(Event, model, AlreadyBookedCaterings, AlreadyBookedRooms); window.ShowDialog(); if (window.DialogResult != null && window.DialogResult.Value) { AlreadyBookedCaterings.Remove(model); EventItemsAlreadyBooked.Remove(item); _event.Event.LastEditDate = DateTime.Now; _event.RefreshItems(); } } else if (item.Instance.GetType() == typeof(EventGolfModel)) { var model = (EventGolfModel)item.Instance; var window = new AddEventGolfItemView(Event, model, AlreadyBookedGolfs); window.ShowDialog(); if (window.DialogResult != null && window.DialogResult.Value) { AlreadyBookedGolfs.Remove(model); EventItemsAlreadyBooked.Remove(item); _event.Event.LastEditDate = DateTime.Now; _event.RefreshItems(); } } else if (item.Instance.GetType() == typeof(EventRoomModel)) { var model = (EventRoomModel)item.Instance; var window = new AddRoomItemView(Event, model, AlreadyBookedCaterings, AlreadyBookedRooms); window.ShowDialog(); if (window.DialogResult != null && window.DialogResult.Value) { AlreadyBookedRooms.Remove(model); EventItemsAlreadyBooked.Remove(item); _event.Event.LastEditDate = DateTime.Now; _event.RefreshItems(); } } RaisePropertyChanged("EnableParentWindow"); if (EventItemsAlreadyBooked.Count == 0) { RaisePropertyChanged("CloseDialog"); } }
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 DeleteItemCommandExecuted(EventItemModel item) { bool? dialogResult = null; string confirmText = Properties.Resources.MESSAGE_ASK_BEFORE_DELETING_ITEM; RaisePropertyChanged("DisableParentWindow"); RadWindow.Confirm(new DialogParameters() { Owner = Application.Current.MainWindow, Content = confirmText, Closed = (sender, args) => { dialogResult = args.DialogResult; } }); RaisePropertyChanged("EnableParentWindow"); if (dialogResult != true) { return; } if (item.Instance.GetType() == typeof(EventCateringModel)) { var model = (EventCateringModel)item.Instance; // Remove booked products model.EventBookedProducts.ForEach(RemoveEventBookedProductAndCharges); AlreadyBookedCaterings.Remove(model); _event.EventCaterings.Remove(model); _eventsDataUnit.EventCateringsRepository.Delete(model.EventCatering); } else if (item.Instance.GetType() == typeof(EventGolfModel)) { var model = (EventGolfModel)item.Instance; // Remove booked products model.EventBookedProducts.ForEach(RemoveEventBookedProductAndCharges); if (model.EventGolf.LinkedEventGolfId != null) { if (model.EventGolf.EventGolf1 == null) { _eventsDataUnit.EventGolfsRepository.DetachGolfEvent((Guid)model.EventGolf.LinkedEventGolfId); } else { _eventsDataUnit.EventGolfsRepository.Delete(model.EventGolf.EventGolf1); } } AlreadyBookedGolfs.Remove(model); _event.EventGolfs.Remove(model); _eventsDataUnit.EventGolfsRepository.Delete(model.EventGolf); } else if (item.Instance.GetType() == typeof(EventRoomModel)) { var model = (EventRoomModel)item.Instance; // Remove booked products model.EventBookedProducts.ForEach(RemoveEventBookedProductAndCharges); AlreadyBookedRooms.Remove(model); _event.EventRooms.Remove(model); _eventsDataUnit.EventRoomsRepository.Delete(model.EventRoom); } EventItemsAlreadyBooked.Remove(item); _event.Event.LastEditDate = DateTime.Now; _event.RefreshItems(); if (EventItemsAlreadyBooked.Count == 0) { RaisePropertyChanged("CloseDialog"); } }