Exemplo n.º 1
0
        public void AddNewActivity_ShouldAddThatToDb()
        {
            var newActivity = new Activity()
            {
                Name = "NewActivity",
            };

            var result = _activityManager.AddActivity(newActivity);

            Assert.AreEqual(true, result);
            Assert.AreEqual("NewActivity", _activityManager.GetAllActivities().SingleOrDefault(n => n.Name == "NewActivity").Name);
        }
Exemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public ActionResult CreateActivity(ActivityViewModel activity)
        {
            var result = new Activity()
            {
                Name = activity.Name,
            };

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Namnet får inte vara tomt.");
                return(View(activity));
            }

            var activityWasInserted = _activityManager.AddActivity(result);

            if (activityWasInserted)
            {
                return(RedirectToAction("AllSessionsForActivity", "ActivitySummary", new { id = result.Id }));
            }
            else
            {
                ModelState.AddModelError("", "En aktivitet med samma namn existerar redan.");
                return(View(activity));
            }
        }
Exemplo n.º 3
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());
            }
        }
Exemplo n.º 4
0
        public void UseCase1_AddingActivityWithEverything_ShouldReturnExpected()
        {
            // 1. SKAPA AKTIVITET
            var activityToAdd = new Activity()
            {
                Name = "NewActivity",
            };

            _activityManager.AddActivity(activityToAdd);

            // 2. SKAPA SESSION
            var sessionToAdd = new Session()
            {
                Name       = "NewSession",
                ActivityId = activityToAdd.Id,
                StartDate  = null,
                EndDate    = null,
                HrPersonId = null,
                LocationId = null,
            };

            _sessionManager.AddSession(sessionToAdd);

            // 3. LÄGG TILL DELTAGARE
            _personManager.AddParticipantToSession(1, sessionToAdd.Id);
            _personManager.AddParticipantToSession(2, sessionToAdd.Id);
            _personManager.AddParticipantToSession(3, sessionToAdd.Id);

            // 4. SPARA KOMMENTAR OCH UTVÄRDERING
            _sessionManager.SaveCommentsForSession(sessionToAdd.Id, "New Comment");
            _sessionManager.SaveEvaluationForSession(sessionToAdd.Id, "New Eval");

            // 5. TA BORT DELTAGARE
            _personManager.RemoveParticipantFromSession(3, sessionToAdd.Id);

            // TEST RESULTS
            var expectedParticipantsCount = 2;

            Assert.AreEqual(expectedParticipantsCount, _personManager.GetAllParticipantsForSession(sessionToAdd.Id).Count());
            Assert.AreEqual("New Comment", _sessionManager.GetSessionById(sessionToAdd.Id).Comments);
            Assert.AreEqual("New Eval", _sessionManager.GetSessionById(sessionToAdd.Id).Evaluation);
        }
Exemplo n.º 5
0
        public IActionResult PostIdeationReplyApp([FromBody] IdeationReplyAppDto ideationReplyApp)
        {
            Ideation ideation = _ideationManager.GetIdeationWithReplies(ideationReplyApp.IdeationId);

            User user = _usermanager.FindByEmailAsync(HttpContext.User.Claims.FirstOrDefault(c => c.Type == "Email").Value).Result;

            IdeationReply newReply = new IdeationReply()
            {
                Ideation = ideation,
                Title    = ideationReplyApp.Title,
                Answers  = new List <Answer>(),
                Votes    = new List <Vote>(),
                Created  = DateTime.Now,
                Comments = new List <Comment>(),
                User     = user,
                Reports  = new List <IdeationReport>()
            };

            int index = 0;

            foreach (var dto in ideationReplyApp.Answers)
            {
                Answer newAnswer = null;

                switch (dto.FieldType)
                {
                case FieldType.OpenText:
                    newAnswer = new OpenTextAnswer()
                    {
                        QuestionIndex = dto.QuestionIndex,
                        Value         = dto.Reply
                    };
                    break;

                case FieldType.SingleChoice:
                case FieldType.DropDown:
                    newAnswer = new SingleChoiceAnswer()
                    {
                        QuestionIndex  = dto.QuestionIndex,
                        SelectedChoice = dto.SelectedChoice
                    };
                    break;

                case FieldType.MultipleChoice:
                    newAnswer = new MultipleChoiceAnswer()
                    {
                        QuestionIndex   = dto.QuestionIndex,
                        SelectedChoices = dto.MultipleAnswer
                    };
                    break;

                case FieldType.Location:
                    newAnswer = new LocationAnswer()
                    {
                        QuestionIndex = dto.QuestionIndex,
                        Value         = new Location()
                        {
                            Latitude  = dto.LocationAnswer.Latitude,
                            Longitude = dto.LocationAnswer.Longitude,
                            ZoomLevel = dto.LocationAnswer.ZoomLevel,
                        }
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                newAnswer.OrderIndex = index++;
                newReply.Answers.Add(newAnswer);
            }

            // Create activity
            var activity = CreateActivity(ActivityType.IdeationReply, user, ideation.Project.Platform);

            activity.IdeationReply = newReply;
            _activityManager.AddActivity(activity);

            // Save everything
            _unitOfWorkManager.Save();

            // Push activity
            var activityVm = new ActivityViewModel(activity);

            PushWebsockets(activityVm).Wait();

            return(Ok());
        }
Exemplo n.º 6
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);
            }
        }