protected override ActionResult ReturnOnSaveForProject(Project project)
 {
     if (project.DataManagementPlan == null)
     {
         return RedirectToAction("CopyDmp", new {id = project.Id});
     }
     return RedirectToAction("Edit", "Dmp", new { project.DataManagementPlan.Id });
 }
 public static DataCollectionViewModelStep1 MapFrom(this DataCollectionViewModelStep1 vm, Project project, DataCollection collection = null)
 {
     if (vm == null || project == null)
     {
         return vm;
     }
     if (collection != null)
     {
         vm.InjectFrom(collection);
     }
     vm.ProjectTitle = project.Title;
     return vm;
 }
        private void AddProjectToFormCollection(Project project)
        {

            foreach (var forCode in project.FieldsOfResearch)
            {
                var value = string.Format("{0}:{1}:{2}", forCode.Id, forCode.FieldOfResearch.Id, forCode.FieldOfResearch.Name);
                _form.Add("ForCodeRows", value);
            }

            foreach (var seoCode in project.SocioEconomicObjectives)
            {
                var value = string.Format("{0}:{1}:{2}", seoCode.Id, seoCode.SocioEconomicObjective.Id, seoCode.SocioEconomicObjective.Name);
                _form.Add("SeoCodeRows", value);
            }
        }
        public static DataManagementPlanViewModel MapFrom(this DataManagementPlanViewModel vm, Project entity)
        {
            if (vm == null || entity == null)
                return vm;

            vm.ProjectId = entity.Id;
            vm.ProjectDescription = entity.Description;
            vm.ProjectTitle = entity.Title;
            vm.PrincipalInvestigator = entity.Parties.Where(p => p.Party.UserId != null && p.Relationship == ProjectRelationship.PrincipalInvestigator).Single().Party;
            vm.Status = entity.ProvisioningStatus;
            vm.InjectFrom<SameNameWithRecursion>(entity.DataManagementPlan);
            vm.UrdmsUsers = entity.Parties
                .Where(
                    p =>
                    p.Relationship != ProjectRelationship.PrincipalInvestigator &&
                    !string.IsNullOrWhiteSpace(p.Party.UserId))
                .Select(
                    p =>
                    new UrdmsUserViewModel
                    {
                        UserId = p.Party.UserId,
                        FullName = p.Party.FullName,
                        PartyId = p.Party.Id,
                        Id = p.Id,
                        Relationship = (int)p.Role
                    })
                .ToList();

            vm.NonUrdmsUsers = entity.Parties
                .Where(p => string.IsNullOrWhiteSpace(p.Party.UserId))
                .Select(
                    p =>
                    new NonUrdmsUserViewModel
                    {
                        FullName = p.Party.FullName,
                        PartyId = p.Party.Id,
                        Id = p.Party.Id,
                        Relationship = (int)p.Role
                    })
                .ToList();

            return vm;
        }
 protected override bool VerifyProjectRequest(Project entity, out ActionResult result)
 {
     if (entity == null)
     {
         result = View("ProjectNotFound");
         return false;
     }
     if (!this.CurrentUser.IsPrincipalInvestigatorFor(entity))
     {
         result = View("NoProjectAccessRight");
         return false;
     }
     if (entity.SourceProjectType == SourceProjectType.DEPOSIT)
     {
         result = View("IncorrectProjectType");
         return false;
     }
     result = new EmptyResult();
     return true;
 } 
        public void Return_a_vaild_users_list_for_a_vaild_projectkey()
        {
            var project = new Project
                             {
                                 Title = "Project1",
                                 Description = "Project details",
                             };

            var projectParty = Builder<ProjectParty>.CreateNew()
                .With(p => p.Id = 0)
                .And(p => p.Project = project)
                .And(p => p.Party = Builder<Party>.CreateNew().With(u => u.Id = 0).Build())
                .And(p => p.Role = AccessRole.Owners)
                .Build();

            project.Parties.Add(projectParty);

            _repository.Save(project);

            var createdEntity = _repository.Get(project.Id);
            Assert.That(createdEntity, Is.Not.Null, "Data Management Plan not retrieved");
            Assert.That(createdEntity.Parties, Is.Not.Null, "User access list is null");
            Assert.That(createdEntity.Parties.Count, Is.EqualTo(1), "User access list size is not 1");
        }
 protected override ActionResult ReturnOnSaveForProject(Project project)
 {
     if (project.DataDeposit != null)
     {
         return RedirectToAction("Index", "Project");
     }
     return RedirectToAction("New", new { projectId = project.Id });
 }
        protected override ActionResult ReturnOnPostForProject(Project project)
        {
            project.SourceProjectType = SourceProjectType.DEPOSIT;
            project.Status = ProjectStatus.Completed;
            project.Funders.Clear();
            ProjectRepository.Save(project);

            return ReturnOnSaveForProject(project);
        }
        private DataCollection SetUpFullDataCollection(Project project)
        {
            var dataCollection = Builder<DataCollection>.CreateNew()
                .With(o => o.ProjectId = project.Id)
                .And(o => o.Id = project.DataCollections.Count == 0 ? 1 : project.DataCollections.Max(q => q.Id) + 1)
                .And(o => o.IsFirstCollection = !project.DataCollections.Any(q => q.IsFirstCollection))
                .And(o => o.Availability = DataSharingAvailability.AfterASpecifiedEmbargoPeriod)
                .And(o => o.AvailabilityDate = DateTime.Today.AddMonths(1))
                .And(o => o.AwareOfEthics = PickHelper.RandomBoolean())
                .And(o => o.DataCollectionIdentifier = PickHelper.RandomEnumExcept(DataCollectionIdentifier.None))
                .And(o => o.DataLicensingRights = PickHelper.RandomEnumExcept<DataLicensingType>())
                .And(o => o.EndDate = DateTime.Today.AddMonths(9))
                .And(o => o.Keywords = project.Keywords)
                .And(o => o.ShareAccess = PickHelper.RandomEnumExcept(ShareAccess.NoAccess))
                .And(o => o.StartDate = DateTime.Today.AddMonths(-3))
                .And(o => o.Type = PickHelper.RandomEnumExcept<DataCollectionType>())
                .Do(o =>
                        {
                            o.FieldsOfResearch.AddRange(Builder<DataCollectionFieldOfResearch>.CreateListOfSize(project.FieldsOfResearch.Count)
                                .All()
                                .With(q => q.FieldOfResearch = project.FieldsOfResearch[q.Id - 1].FieldOfResearch)
                                .Build());

                            o.SocioEconomicObjectives.AddRange(Builder<DataCollectionSocioEconomicObjective>.CreateListOfSize(project.SocioEconomicObjectives.Count)
                                .All()
                                .With(q => q.SocioEconomicObjective = project.SocioEconomicObjectives[q.Id - 1].SocioEconomicObjective)
                                .Build());

                            o.Parties.AddRange(Builder<DataCollectionParty>.CreateListOfSize(project.Parties.Count)
                                .All()
                                .With(q => q.Party = project.Parties[q.Id - 1].Party)
                                .And(q => q.Relationship = project.Parties[q.Id - 1].Relationship == ProjectRelationship.PrincipalInvestigator 
                                    ? DataCollectionRelationshipType.Manager : PickHelper.RandomEnumExcept(DataCollectionRelationshipType.Manager, DataCollectionRelationshipType.None))
                                .Build());
                        })
                .Build();
            project.DataCollections.Add(dataCollection);
            dataCollection.Parties.Do(o => o.DataCollection = dataCollection);

            _dataCollectionRepository.Get(Arg.Is(dataCollection.Id)).Returns(dataCollection);
            return dataCollection;
        }
 protected abstract ActionResult ReturnOnSaveForProject(Project project);
 private IEnumerable<DataCollection> SetUpFullDataCollections(Project project, int instances = 1)
 {
     return Enumerable.Range(1,instances).Select(instance => SetUpFullDataCollection(project));
 }
        public static bool IsEqualTo(this Project source, Project other, ProjectCompareTypes comparison)
        {
            var expressions = GetExpressions(comparison).ToList();
            if (expressions.IsEmpty())
            {
                return false;
            }
            var expression = expressions.First();
            foreach (var item in expressions.Skip(1))
            {
                expression = expression.AndAlso(item);
            }
            var lambda = expression.Compile();
            return lambda(source, other);

        }
 protected virtual ActionResult ReturnOnPostForProject(Project project)
 {
     ProjectRepository.Save(project);
     return ReturnOnSaveForProject(project);
 }
 protected abstract bool VerifyProjectRequest(Project entity, out ActionResult result);
        public static DataCollectionReadOnlyViewModel MapFrom(this DataCollectionReadOnlyViewModel vm, DataCollection collection, Project project)
        {
            if (vm == null || collection == null || project == null)
                return vm;

            vm.InjectFrom(collection);

            MapForCodes(vm.FieldsOfResearch, collection.FieldsOfResearch);
            MapSeoCodes(vm.SocioEconomicObjectives, collection.SocioEconomicObjectives);
            vm.Manager = MapManager(collection.Parties);
            vm.UrdmsUsers = MapUrdmsUsers(collection.Parties);
            vm.NonUrdmsUsers = MapNonUrdmsUsers(collection.Parties);
            vm.ProjectTitle = project.Title;

            return vm;
        }
 protected override ActionResult ReturnOnPostForProject(Project project)
 {
     project.SourceProjectType = SourceProjectType.DMP;
     ProjectRepository.Save(project);
     return ReturnOnSaveForProject(project);
 }
        public void Save(Project project)
        {
            EnsureNonDuplicationOfParties(project.Parties);

            _session.SaveOrUpdate(project);
            _session.Flush();
        }
        private static Dictionary<string, string> CreateUserRolesDictionary(Project project)
        {
            var owners = project.Parties.Where(r => r.Role == AccessRole.Owners).ToList();
            var members = project.Parties.Where(r => r.Role == AccessRole.Members).ToList();
            var visitors = project.Parties.Where(r => r.Role == AccessRole.Visitors).ToList();

            var userRoles = new Dictionary<string, string>();
            if (owners.Count > 0)
            {
                userRoles.Add("Owners", string.Join(",", owners.Select(i => i.Party.UserId).ToArray()));
            }
            if (members.Count > 0)
            {
                userRoles.Add("Members", string.Join(",", members.Select(i => i.Party.UserId).ToArray()));
            }
            if (visitors.Count > 0)
            {
                userRoles.Add("Visitors", string.Join(",", visitors.Select(i => i.Party.UserId).ToArray()));
            }
            return userRoles;
        }
 public static bool IsPrincipalInvestigatorFor(this ICurtinUser user, Project entity)
 {
     return entity.Parties.Any(o => o.Party.UserId.Equals(user.CurtinId, StringComparison.InvariantCultureIgnoreCase) && o.Relationship == ProjectRelationship.PrincipalInvestigator);
 }
        private void AddProjectToFormCollection(Project project, IEnumerable<Party> deletedParties = null)
        {
            const string urdmsUsersRow = "urdms.users.row";
            const string nonUrdmsUserKey = "nonurdms.users.row";
            const string urdmsUserFormat = "{0},{1},{2},{3},{4}";
            const string nonUrdmsUserFormat = "{0},{1},{2},{3}";
			const string relationshipUrdmsUserKeyFormat = "UrdmsUserRelationship{0}";
			const string relationshipNonUrdmsUserKeyFormat = "NonUrdmsUserRelationship{0}";
            const string removeUrdmsUserKeyFormat = "RemoveUrdmsUser{0}";
			const string removeNonUrdmsUserKeyFormat = "RemoveNonUrdmsUser{0}";

            foreach (var projectParty in project.Parties)
            {
                var party = projectParty.Party;
                string userKey;
                string userValue;
                var isUrdmsUser = party.UserId != null;
                if (!isUrdmsUser)
                {
                    userKey = nonUrdmsUserKey;
                    userValue = string.Format(nonUrdmsUserFormat, projectParty.Id, party.FullName.GetHashCode(), party.FullName, projectParty.Role);
                }
                else
                {
                    userKey = urdmsUsersRow;
                    userValue = string.Format(urdmsUserFormat, projectParty.Id, party.FullName.GetHashCode(), party.FullName, party.UserId, projectParty.Role);
                }

                _form.Add(userKey, userValue);
                var relationshipKeyFormat = isUrdmsUser ? relationshipUrdmsUserKeyFormat : relationshipNonUrdmsUserKeyFormat;
                var removeUserKeyFormat = isUrdmsUser ? removeUrdmsUserKeyFormat : removeNonUrdmsUserKeyFormat;
                var relationshipKey = string.Format(relationshipKeyFormat, projectParty.Id == 0 ? party.FullName.GetHashCode() : party.Id);
                var relationshipValue = ((int)projectParty.Relationship).ToString();
                _form.Add(relationshipKey, relationshipValue);
                var removeUserKey = string.Format(removeUserKeyFormat, projectParty.Id == 0 ? party.FullName.GetHashCode() : projectParty.Id);
                _form.Add(removeUserKey, "false");
                if (deletedParties != null && deletedParties.Any(o => o.Id == party.Id))
                {
                    _form.Add(removeUserKey, "true");
                }

            }

        }
        public void SetUp()
        {
            _autoSubstitute = AutoSubstituteContainer.Create();

            _projectRepository = _autoSubstitute.Resolve<IProjectRepository>();
            _dataCollectionRepository = _autoSubstitute.Resolve<IDataCollectionRepository>();
            _controller = _autoSubstitute.GetController<ConfirmController>();
            _lookup = _autoSubstitute.Resolve<ICurtinUserService>();
            var user = CreateUser("XX12345");
            var dmp = Builder<DataManagementPlan>.CreateNew()
                .With(o => o.NewDataDetail = Builder<NewDataDetail>.CreateNew().Build())
                .And(o => o.ExistingDataDetail = Builder<ExistingDataDetail>.CreateNew().Build())
                .And(o => o.DataSharing = Builder<DataSharing>.CreateNew().Build())
                .And(o => o.DataRelationshipDetail = Builder<DataRelationshipDetail>.CreateNew().Build())
                .Build();
            var dd = Builder<DataDeposit>.CreateNew().Build();
            _project = Builder<Project>.CreateNew()
                .With(o => o.DataManagementPlan = dmp)
                .And(o => o.DataDeposit = dd)
                .And(p => p.Description = "TestProject")
                .And(o => o.Keywords = "1,2,3,4,5,6,7,8,9,10,11,12")
                .Build();
            _project.FieldsOfResearch.AddRange(Builder<ProjectFieldOfResearch>
                                                   .CreateListOfSize(5)
                                                   .All()
                                                   .With(p => p.FieldOfResearch = Builder<FieldOfResearch>.CreateNew().Build())
                                                   .Build());
            _project.SocioEconomicObjectives.AddRange(Builder<ProjectSocioEconomicObjective>
                                                          .CreateListOfSize(7)
                                                          .All()
                                                          .With(p => p.SocioEconomicObjective = Builder<SocioEconomicObjective>.CreateNew().Build())
                                                          .Build());
            _project.Parties.AddRange(Builder<ProjectParty>.CreateListOfSize(8)
                                          .TheFirst(1)
                                          .With(o => o.Role = AccessRole.Members)
                                          .And(o => o.Party = Builder<Party>.CreateNew().With(p => p.Id = 0).Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.Owners)
                                          .And(o => o.Party = Builder<Party>.CreateNew().With(p => p.Id = 0).And(p => p.UserId = user.CurtinId).Build())
                                          .And(o => o.Relationship = ProjectRelationship.PrincipalInvestigator)
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.Visitors)
                                          .And(o => o.Party = Builder<Party>.CreateNew().With(p => p.Id = 0).Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.None)
                                          .And(o => o.Party = Builder<Party>.CreateNew().With(p => p.Id = 0).Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.Members)
                                          .And(
                                              o =>
                                              o.Party =
                                              Builder<Party>.CreateNew().With(p => p.UserId = "FF24587").Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.Visitors)
                                          .And(
                                              o =>
                                              o.Party =
                                              Builder<Party>.CreateNew().With(p => p.UserId = "GA37493").Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.None)
                                          .And(
                                              o =>
                                              o.Party =
                                              Builder<Party>.CreateNew().With(p => p.UserId = "KK25344").Build())
                                          .TheNext(1)
                                          .With(o => o.Role = AccessRole.Owners)
                                          .And(
                                              o =>
                                              o.Party =
                                              Builder<Party>.CreateNew().With(p => p.UserId = "DD25265").Build())
                                          .Build());

            _bus = _autoSubstitute.Resolve<IBus>();
            _projectRepository.Get(Arg.Is(_project.Id)).Returns(_project);
            _projectRepository.GetByDataManagementPlanId(Arg.Is(_project.DataManagementPlan.Id)).Returns(_project);

            var resolver = Substitute.For<IDependencyResolver>();
            DependencyResolver.SetResolver(resolver);
        }
        public void SetUp()
        {
            _project = Builder<Project>.CreateNew()
                .With(o => o.DataManagementPlan = Builder<DataManagementPlan>.CreateNew()
                                                      .With(
                                                          q =>
                                                          q.BackupPolicy =
                                                          Builder<BackupPolicy>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.DataDocumentation =
                                                          Builder<DataDocumentation>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.DataRelationshipDetail =
                                                          Builder<DataRelationshipDetail>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.DataRetention =
                                                          Builder<DataRetention>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.DataSharing =
                                                          Builder<DataSharing>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.DataStorage =
                                                          Builder<DataStorage>.CreateNew().Build())
                                                      .And(q => q.Ethic = Builder<Ethic>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.ExistingDataDetail =
                                                          Builder<ExistingDataDetail>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.Confidentiality =
                                                          Builder<Confidentiality>.CreateNew().Build())
                                                      .And(
                                                          q =>
                                                          q.NewDataDetail =
                                                          Builder<NewDataDetail>.CreateNew().Build())
                                                      .Build())
                .Build();

            _project.SocioEconomicObjectives.AddRange(
                Builder<ProjectSocioEconomicObjective>.CreateListOfSize(4).All().With(
                    q => q.SocioEconomicObjective = Builder<SocioEconomicObjective>.CreateNew().Build()).Build());
            _project.FieldsOfResearch.AddRange(
                Builder<ProjectFieldOfResearch>.CreateListOfSize(5).All().With(
                    q => q.FieldOfResearch = Builder<FieldOfResearch>.CreateNew().Build()).Build());
            _project.Funders.AddRange(
                Builder<ProjectFunder>.CreateListOfSize(1).All().With(
                    q => q.Funder = Pick<Funder>.RandomItemFrom(new[] {Funder.ARC, Funder.NMHRC})).Build());
            _project.Parties.AddRange(Builder<ProjectParty>.CreateListOfSize(6)
                                          .TheFirst(3)
                                          .With(q => q.Party = Builder<Party>.CreateNew()
                                                                   .With(r => r.UserId = null)
                                                                   .Build())
                                          .And(q => q.Relationship = ProjectRelationship.ExternalResearcher)
                                          .And(q => q.Role = AccessRole.Visitors)
                                          .TheNext(2)
                                          .With(q => q.Role = AccessRole.Members)
                                          .And(q => q.Party = Builder<Party>.CreateNew()
                                                                   .With(r => r.UserId = null)
                                                                   .Build())
                                          .And(q => q.Relationship = ProjectRelationship.Investigator)
                                          .TheNext(1)
                                          .With(q => q.Party = Builder<Party>.CreateNew()
                                                                   .With(r => r.UserId = "123456A")
                                                                   .Build())
                                          .And(q => q.Role = AccessRole.Owners)

                                          .And(q => q.Relationship = ProjectRelationship.PrincipalInvestigator)
                                          .Build());

            for (var i = 1; i < 7; i++)
                _project.Parties[i - 1].Party.Id = i;

            _funder = _project.Funders.First();
            _principalInvestigator = _project.Parties.Single(o => o.Role == AccessRole.Owners).Party;

            var users = _project.Parties.Where(pp => pp.Party.Id != _principalInvestigator.Id).ToList();

            _urdmsUsers =
                users.Where(o => !string.IsNullOrWhiteSpace(o.Party.UserId)).Select(o => o.Party).ToList();
            _nonUrdmsUsers =
                users.Where(o => string.IsNullOrWhiteSpace(o.Party.UserId)).Select(o => o.Party).ToList();
            
        }