Beispiel #1
0
        public ActionResult AddPerson(int id, int seminarPersonId, string personType)
        {
            var caseStudy = _casestudyRepository.GetNullableById(id);

            if (caseStudy == null)
            {
                Message = string.Format(Messages.NotFound, "case study", id);
                return(this.RedirectToAction <SeminarController>(a => a.Index()));
            }

            var selectedPerson = _seminarPersonRepository.GetNullableById(seminarPersonId);

            if (selectedPerson == null)
            {
                ModelState.AddModelError("Seminar Person", "Invalid seminar person was selected.");
            }

            // check to make sure the role is valid
            if (personType != StaticIndexes.Role_CaseStudyAuthor && personType != StaticIndexes.Role_CaseExecutive)
            {
                ModelState.AddModelError("Person Type", "Invalid person type was selected.");
            }

            // check to make sure the person doesn't already exist in the list
            if (personType == StaticIndexes.Role_CaseStudyAuthor && caseStudy.CaseAuthors.Any(a => a == selectedPerson))
            {
                ModelState.AddModelError("Seminar Person", "Seminar person already exists as a case author for this case study.");
            }
            if (personType == StaticIndexes.Role_CaseExecutive && caseStudy.CaseExecutives.Any(a => a == selectedPerson))
            {
                ModelState.AddModelError("Seminar Person", "Seminar person already exists as a case executive for this case study.");
            }

            if (ModelState.IsValid)
            {
                if (personType == StaticIndexes.Role_CaseStudyAuthor)
                {
                    caseStudy.CaseAuthors.Add(selectedPerson);
                }
                if (personType == StaticIndexes.Role_CaseExecutive)
                {
                    caseStudy.CaseExecutives.Add(selectedPerson);
                }

                _casestudyRepository.EnsurePersistent(caseStudy);
                Message = string.Format(Messages.Saved, "Case Study");
                return(this.RedirectToAction(a => a.Edit(id, caseStudy.Seminar.Id)));
            }

            var viewModel = CaseStudyPersonViewModel.Create(Repository, caseStudy);

            viewModel.SeminarPersonId = seminarPersonId;
            return(View(viewModel));
        }
Beispiel #2
0
        public ActionResult AddPerson(int id)
        {
            var caseStudy = _casestudyRepository.GetNullableById(id);

            if (caseStudy == null)
            {
                Message = string.Format(Messages.NotFound, "case study", id);
                return(this.RedirectToAction <SeminarController>(a => a.Index()));
            }

            var viewModel = CaseStudyPersonViewModel.Create(Repository, caseStudy);

            return(View(viewModel));
        }