Esempio n. 1
0
        private async Task OnNewBooking()
        {
            var model = new BookingEditModel {
                Status = this.Status
            };

            // Open booking edit dialog.
            var dialogResult = await this.Context.ModalDialog.ShowAsync <BookingEditDialog>(new ModalOptions().SetParameter(nameof(BookingEditDialog.Model), model));

            if (dialogResult.Cancelled)
            {
                return;                          // User has cancelled the action.
            }
            // The model now contains validated data for the new booking.
            var entity = new BookingEntity();

            model.PopulateEntity(entity);

            await SaveBooking(entity);

            await this.Context.Notifications.ShowSuccessAsync(null, "The new booking has been created.");
        }
Esempio n. 2
0
        private async Task OnBookingClicked(BookingEntity booking)
        {
            var model = BookingEditModel.FromEntity(booking);

            // Open booking edit dialog.
            var dialogResult = await this.Context.ModalDialog.ShowAsync <BookingEditDialog>(new ModalOptions().SetParameter(nameof(BookingEditDialog.Model), model));

            if (dialogResult.Cancelled)
            {
                return;                          // User has cancelled the action.
            }
            if ((bool)dialogResult.Data)
            {
                try
                {
                    // Delete booking
                    await this.BookingRepository.DeleteAsync(booking.Id);

                    await this.Context.Notifications.ShowSuccessAsync(null, "The booking has been deleted.");
                }
                catch (Exception ex)
                {
                    await this.Context.Notifications.ShowErrorAsync("Error", ex.Message);
                }

                this.Bookings.Remove(booking);

                await _grid.ReloadAsync();
            }
            else
            {
                // The model now contains validated data for the booking.
                model.PopulateEntity(booking);

                await SaveBooking(booking);

                await this.Context.Notifications.ShowSuccessAsync(null, "The booking has been updated.");
            }
        }