Exemplo n.º 1
0
        public ActionResult Create(Guid id, Investigator investigator)
        {
            var proposal = _proposalRepository.Queryable.Where(a => a.Guid == id).SingleOrDefault();
            var investigatorToCreate = new Investigator();
            investigatorToCreate.Proposal = proposal;

            var redirectCheck = RedirectCheck(this, proposal, investigatorToCreate, id, "add", true, "to");
            if (redirectCheck != null)
            {
                return redirectCheck;
            }

            TransferValues(investigator, investigatorToCreate);

            investigatorToCreate.TransferValidationMessagesTo(ModelState);
            if (investigatorToCreate.IsPrimary && Repository.OfType<Investigator>().Queryable.Where(a => a.Proposal == proposal && a.IsPrimary).Any())
            {
                ModelState.AddModelError("Investigator.IsPrimary", StaticValues.ModelError_MultiplePrimary);
            }

            if (ModelState.IsValid)
            {
                _investigatorRepository.EnsurePersistent(investigatorToCreate);

                Message = string.Format(StaticValues.Message_CreatedSuccessfully, "Investigator");

                return this.RedirectToAction<ProposalController>(a => a.Edit(id));
            }
            else
            {
                var viewModel = InvestigatorViewModel.Create(Repository, proposal);
                viewModel.Investigator = investigatorToCreate;

                return View(viewModel);
            }
        }