Esempio n. 1
0
        public ActionResult Create(EventBookingViewModel eventBookings)
        {
            if (ModelState.IsValid)
            {
                if (eventBookings.EventID != 0 && eventBookings.VenueID != 0 && eventBookings.CatererID != 0 && eventBookings.CustomerID != 0)
                {
                    if (eventBookings.StartTime < eventBookings.EndTime)
                    {
                        if (eventBookingMnger.InsertNewEventBooking(eventBookings.EventID, eventBookings.StartTime, eventBookings.EndTime, eventBookings.EventDate, eventBookings.VenueID, eventBookings.CustomerID, eventBookings.CatererID, 1000))
                        {
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            return(RedirectToAction("Error"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Event start time should be less than event end time.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Please enter values for required fields.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Error Occured.");
            }
            EventBookingViewModel modelObj = new EventBookingViewModel();
            EventType             typ      = new EventType(0, "Please Select", "");

            modelObj.EventType = eventBookingMnger.GetEventTypeList();
            modelObj.EventType.Insert(0, typ);
            modelObj.EventID = 0;

            Venue ven = new Venue(0, "Please Select");

            modelObj.Venue = eventBookingMnger.GetVenueList();
            modelObj.Venue.Insert(0, ven);
            modelObj.VenueID = 0;

            Caterers cat = new Caterers(0, "Please Select");

            modelObj.Caterer = eventBookingMnger.GetCaterersList();
            modelObj.Caterer.Insert(0, cat);
            modelObj.CatererID = 0;
            Customer cust = new Customer();

            cust.CustomerID   = 0;
            cust.FirstName    = "Please Select";
            modelObj.Customer = customerManager.GetCustomerList();
            modelObj.Customer.Insert(0, cust);
            modelObj.CustomerID = 0;
            return(View(modelObj));
        }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DateTime eventDate   = DateTime.Parse(dpEventDate.SelectedDate.ToString());
                TimeSpan startTime   = TimeSpan.Parse(txtStartTime.Text);
                TimeSpan endTime     = TimeSpan.Parse(txtEndTime.Text);
                int      eventTypeId = int.Parse(cmbEventName.SelectedValue.ToString());
                int      venueId     = int.Parse(cmbVenue.SelectedValue.ToString());
                int      customerId  = int.Parse(cmbCustomer.SelectedValue.ToString());
                int      catererId   = int.Parse(cmbCaterers.SelectedValue.ToString());

                int uID = 1001;

                if (!isEdit)
                {
                    if ((eventDate.ToString() != string.Empty) && (startTime.ToString() != string.Empty) &&
                        (endTime.ToString() != string.Empty) && (eventTypeId.ToString() != string.Empty &&
                                                                 venueId.ToString() != string.Empty && customerId.ToString() != string.Empty))
                    {
                        if (eventBookingManager.InsertNewEventBooking(eventTypeId, startTime, endTime, eventDate, venueId, customerId, catererId, uID))
                        {
                            MessageBox.Show("New event has been booked.", "New Record", MessageBoxButton.OK, MessageBoxImage.Information);

                            DisplayEventBookingsData();
                            CleanEntryForm();
                            isEdit              = false;
                            btnSave.IsEnabled   = false;
                            btnCancel.IsEnabled = false;
                            btnEdit.IsEnabled   = true;
                            // btnDelete.IsEnabled = true;
                            grdEventEntryForm.IsEnabled = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter all required fields", "New Record", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }

                if (isEdit)
                {
                    if (grdEventBookingList.SelectedItem != null)
                    {
                        try
                        {
                            var selectedBooking = (EventBookings)grdEventBookingList.SelectedItem;

                            MessageBoxResult _result = MessageBox.Show("Are you sure you want to update this booking record, Booking Id - " + selectedBooking.BookingID, "Edit Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

                            if (_result == MessageBoxResult.Yes)
                            {
                                if ((eventDate.ToString() != string.Empty) && (startTime.ToString() != string.Empty) &&
                                    (endTime.ToString() != string.Empty) && (eventTypeId.ToString() != string.Empty &&
                                                                             venueId.ToString() != string.Empty && customerId.ToString() != string.Empty))
                                {
                                    EventBookingsO _editEvent = new EventBookingsO();

                                    _editEvent.EventDate     = eventDate;
                                    _editEvent.StartTime     = startTime;
                                    _editEvent.EndTime       = endTime;
                                    _editEvent.EventTypeID   = eventTypeId;
                                    _editEvent.VenueID       = venueId;
                                    _editEvent.CustomerID    = customerId;
                                    _editEvent.CaterersID    = catererId;
                                    _editEvent.BookingID     = selectedBooking.BookingID;
                                    _editEvent.UserProfileID = uID;



                                    if (eventBookingManager.UpdateEventBooking(_editEvent))
                                    {
                                        MessageBox.Show("Selected booking has been updated.");
                                        DisplayEventBookingsData();
                                        CleanEntryForm();
                                        isEdit              = false;
                                        btnSave.IsEnabled   = false;
                                        btnCancel.IsEnabled = false;
                                        btnEdit.IsEnabled   = true;
                                        //btnDelete.IsEnabled = true;
                                    }
                                }
                            }
                        }
                        catch
                        {
                            MessageBox.Show("You must select a line in grid with customer in it.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }