コード例 #1
0
        public ActionResult CreateActivity(ActivityVM activity)
        {
            try
            {
                int activityID = _activityManager.AddActivity(activity);

                _activityManager.AddActivitySchedule(activityID, activity.Start, activity.End);

                return(RedirectToAction("ActivityList", new { message = "Activity Created." }));
            }
            catch (Exception)
            {
                ViewBag.ActivityTypeList = _activityManager.RetrieveAllActivityTypes();
                return(View());
            }
        }
コード例 #2
0
        // This event handler fires when the save button is clicked. It gathers all the information from the text boxes and then, based upon if _addMode is true or false,
        // either updates an activity or creates a new one.
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            ActivityVM activityToSave = new ActivityVM();

            if (txtActivityName.Text == "")
            {
                MessageBox.Show("You must enter an activity name.");
                txtActivityName.Focus();
                return;
            }
            if (txtAddress1.Text == "")
            {
                MessageBox.Show("You must enter an address.");
                txtAddress1.Focus();
                return;
            }
            if (txtCity.Text == "")
            {
                MessageBox.Show("You must enter a city name.");
                txtCity.Focus();
                return;
            }
            if (txtDescription.Text == "")
            {
                MessageBox.Show("You must enter a description.");
                txtDescription.Focus();
                return;
            }

            if (txtEnd.Text == "")
            {
                MessageBox.Show("You must enter a date and time.");
                txtEnd.Focus();
                return;
            }

            try
            {
                DateTime end = DateTime.Parse(txtEnd.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("You must enter valid date and time.");
                txtEnd.Focus();
                return;
            }


            if (txtLocation.Text == "")
            {
                MessageBox.Show("You must enter a location");
                txtLocation.Focus();
                return;
            }

            if (txtStart.Text == "")
            {
                MessageBox.Show("You must enter a date and time");
                txtStart.Focus();
                return;
            }

            try
            {
                DateTime start = DateTime.Parse(txtStart.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("You must enter valid date and time.");
                txtEnd.Focus();
                return;
            }

            if (txtState.Text == "")
            {
                MessageBox.Show("You must enter a state");
                txtState.Focus();
                return;
            }
            if (txtZip.Text == "")
            {
                MessageBox.Show("You must enter a Zip code");
                txtZip.Focus();
                return;
            }
            if (cmbActivityType == null)
            {
                MessageBox.Show("You must choose a Activity Type");
                cmbActivityType.Focus();
                return;
            }

            try
            {
                ActivityVM newActivity = new ActivityVM()
                {
                    ActivityName   = txtActivityName.Text,
                    ActivityTypeID = cmbActivityType.SelectedItem.ToString(),
                    LocationName   = txtLocation.Text,
                    Address1       = txtAddress1.Text,
                    Address2       = txtAddress2.Text,
                    City           = txtCity.Text,
                    State          = txtState.Text,
                    Zip            = txtZip.Text,
                    Description    = txtDescription.Text,
                    End            = DateTime.Parse(txtEnd.Text),
                    Start          = DateTime.Parse(txtStart.Text),
                };



                if (_addMode)
                {
                    int activityID = _activityManager.AddActivity(newActivity);

                    _activityManager.AddActivitySchedule(activityID, DateTime.Parse(txtStart.Text), DateTime.Parse(txtEnd.Text));

                    MessageBox.Show("Activity: " + newActivity.ActivityName + " created.");

                    _addMode = false;

                    populateActivityList();

                    btnSave.Visibility = Visibility.Hidden;
                }

                else
                {
                    newActivity.ActivityID = _activity.ActivityID;

                    _activityManager.EditActivity(_activity, newActivity);

                    _scheduleManager.EditActivitySchedule(_activity, newActivity);

                    populateUserActivityList();
                    populateActivityList();
                    btnSave.Visibility = Visibility.Hidden;
                    btnEdit.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }