public ActionResult Edit(DataManagementPlanViewModel vm) { var project = _projectRepository.GetByDataManagementPlanId(vm.Id); if (project == null) { return View("DmpNotFound"); } if (!this.CurrentUser.IsPrincipalInvestigatorFor(project)) { return View("NoProjectAccessRight"); } if (vm.Step < 1 || vm.Step > MaxStep) { return View("PageNotFound"); } if (!ModelState.IsValid) { return View(string.Format("Step{0}", vm.Step), vm); } var currentStep = vm.Step; vm.Step = GetStep(vm.Step); var projectModel = new ProjectViewModel { DataManagementPlan = vm }; // Copy project details from project entity projectModel.MapFrom(project, false); // delete users when in the appropriate step project.MapFrom(projectModel, currentStep == UserManagementStep); var urdmsUsers = project.Parties.Where(o => !string.IsNullOrWhiteSpace(o.Party.UserId) && o.Party.Id == 0).Select(o => o.Party); // only update new parties this.UpdateUrdmsPartyDetails(urdmsUsers.ToList()); _projectRepository.Save(project); //Dmp form completion timer for steps 1-4. Only on next button submit. if (currentStep < vm.Step) { _timerRepository.Save(new FormTimer { UserId = CurrentUser.CurtinId, EndTime = DateTime.Now, Id = vm.Id, StartTime = vm.Start, Step = vm.Step - 1 }); } return RedirectToAction("Edit", new { id = vm.Id, step = vm.Step }); }
public ActionResult New(DataDepositViewModel vm) { var project = ProjectRepository.Get(vm.ProjectId); if (project == null) { return View("ProjectNotFound"); } if (!this.CurrentUser.IsPrincipalInvestigatorFor(project)) { return View("NoProjectAccessRight"); } if (project.SourceProjectType != SourceProjectType.DEPOSIT) { return View("CannotCreateDataDeposit"); } if (project.DataDeposit != null) { return View("DataDepositAlreadyExists"); } var projectModel = new ProjectViewModel { DataDeposit = vm }; // Copy project details from project entity projectModel.MapFrom(project, false, false); project.MapFrom(projectModel); var urdmsUsers = project.Parties.Where(o => !string.IsNullOrWhiteSpace(o.Party.UserId) && o.Party.Id == 0).Select(o => o.Party); // only update new parties this.UpdateUrdmsPartyDetails(urdmsUsers.ToList()); ProjectRepository.Save(project); switch (project.ProvisioningStatus) { case ProvisioningStatus.NotStarted: return RedirectToAction("ReviewDataDeposit", "Confirm", new { projectId = vm.ProjectId }); default: throw new InvalidOperationException("Uncatered Dmp Status"); } }
public void Map_to_a_basic_project_view_model() { var model = new ProjectViewModel(); model.MapFrom(_project); Assert.That(model,Is.Not.Null,"View model is null"); Assert.That(model.Id,Is.EqualTo(_project.Id),"View model has incorrect id"); Assert.That(model.Title,Is.Not.Null,"Project name is empty"); Assert.That(model.SocioEconomicObjectives.Count,Is.EqualTo(_project.SocioEconomicObjectives.Count),"Socio economic objectives count is incorrect"); Assert.That(model.FieldsOfResearch.Count,Is.EqualTo(_project.FieldsOfResearch.Count),"Fields of research count is incorrect"); Assert.That(model.SocioEconomicObjectives.All(o => _project.SocioEconomicObjectives.Any(q => q.SocioEconomicObjective.Id == o.Code.Id)),"Incorrect socio economic objectives"); Assert.That(model.FieldsOfResearch.All(o => _project.FieldsOfResearch.Any(q => q.FieldOfResearch.Id == o.Code.Id)),"Incorrect fields of research"); Assert.That(model.DataManagementPlan, Is.Null, "Data management plan is not null"); Assert.That(model.PrincipalInvestigator, Is.Not.Null, "Principal Investigator is null"); Assert.That(model.PrincipalInvestigator.UserId, Is.EqualTo(_principalInvestigator.UserId), "Principal investigator is incorrectly retrieved"); }