public void PopulateEntity(BookingEntity entity)
 {
     entity.Status           = this.Status;
     entity.CheckInDate      = this.CheckInDate.GetValueOrDefault();
     entity.CheckOutDate     = this.CheckOutDate.GetValueOrDefault();
     entity.Room             = this.Room;
     entity.NumberOfAdults   = this.NumberOfAdults.GetValueOrDefault();
     entity.NumberOfChildren = this.NumberOfChildren.GetValueOrDefault();
     entity.GuestFirstName   = this.GuestFirstName;
     entity.GuestLastName    = this.GuestLastName;
     entity.GuestEmail       = this.GuestEmail;
     entity.GuestPhone       = this.GuestPhone;
 }
 public static BookingEditModel FromEntity(BookingEntity entity)
 {
     return(new BookingEditModel
     {
         IsNew = false,
         Status = entity.Status,
         CheckInDate = entity.CheckInDate,
         CheckOutDate = entity.CheckOutDate,
         Room = entity.Room,
         NumberOfAdults = entity.NumberOfAdults,
         NumberOfChildren = entity.NumberOfChildren,
         GuestFirstName = entity.GuestFirstName,
         GuestLastName = entity.GuestLastName,
         GuestEmail = entity.GuestEmail,
         GuestPhone = entity.GuestPhone,
         Comments = entity.Comments
     });
 }
示例#3
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.");
        }
示例#4
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.");
            }
        }
示例#5
0
        private async Task SaveBooking(BookingEntity entity)
        {
            try
            {
                // Save the new booking to the data store.
                await this.BookingRepository.UpsertAsync(entity);

                // Update the current booking list if required.
                if (entity.Status == this.Status && !this.Bookings.Contains(entity))
                {
                    this.Bookings.Add(entity);
                }
                else if (entity.Status != this.Status && this.Bookings.Contains(entity))
                {
                    this.Bookings.Remove(entity);
                }
            }
            catch (Exception ex)
            {
                await this.Context.Notifications.ShowErrorAsync("Error", ex.Message);
            }

            await _grid.ReloadAsync();
        }