コード例 #1
0
        public void EditJavaOneNameToEditedName_ShouldUpdateNameInDB()
        {
            var result = _activityManager.EditActivity(2, "EDITEDNAME");

            Assert.AreEqual(true, result);
            Assert.AreEqual("EDITEDNAME", _activityManager.GetActivityById(2).Name);
        }
コード例 #2
0
        public ActionResult EditActivityPost(ActivityViewModel activityFromInput)
        {
            if (activityFromInput == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            try
            {
                if (_activityManager.EditActivity(activityFromInput.Id, activityFromInput.Name))
                {
                    return(RedirectToAction("ActivityIndex"));
                }

                ModelState.AddModelError("Name", "Aktiviteten existerar redan.");
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("",
                                         "Det går inte att spara ändringarna. Försök igen, och om problemet kvarstår se systemadministratören .");
            }

            return(View("EditActivity", new ActivityViewModel
            {
                Name = activityFromInput.Name
            }));
        }
コード例 #3
0
        public async Task UpdateActivity(UpdateActivityInput input)
        {
            var currentUserId = GetCurrentUserId();
            var activity      = await _activityManager.GetAsync(input.Id);

            var location = input.LocationId.HasValue ? await _locationManager.GetLocationAsync(input.LocationId.Value) : null;

            var tags = await _tagManager.GetTags(input.TagTexts);

            _activityManager.EditActivity(activity, input.Name, input.StartTime, input.EndTime, location, tags, currentUserId);
            _activityManager.EditDescriptions(activity, input.DescriptionIds, currentUserId);
        }
コード例 #4
0
 public ActionResult EditActivity(ActivityVM newActivity)
 {
     try
     {
         var oldActivity = _activityManager.RetrieveActivityByID(newActivity.ActivityID);
         _activityManager.EditActivity(oldActivity, newActivity);
         _scheduleManager.EditActivitySchedule(oldActivity, newActivity);
         return(RedirectToAction("ActivityList", new { message = "Activity Updated." }));
     }
     catch (Exception)
     {
         ViewBag.ActivityTypeList = _activityManager.RetrieveAllActivityTypes();
         return(View());
     }
 }
コード例 #5
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);
            }
        }