示例#1
0
        /// <summary>
        /// Convert a TeamDTO and store it in the repositoy
        /// </summary>
        /// <param name="teamDto"> DTO of the team to be created</param>
        /// <returns></returns>
        public int CreateTeam(TeamDto teamDto)
        {
            if (teamDto.UserIDs == null || teamDto.UserIDs.Length == 0)
            {
                throw new ArgumentException("The team doesn't have any users");
            }

            var teamToAdd = new Team
            {
                Name = teamDto.Name,
                ID = teamDto.Id,
                Metadata = teamDto.Metadata,
                Users = new List<User>()
            };

            foreach (var userId in teamDto.UserIDs)
            {
                if (_teamStorageManager.GetUser(userId) == null)
                {
                    throw new NullReferenceException("User doesn't exist in database");
                }
            }
            foreach (var userId in teamDto.UserIDs)
            {
                teamToAdd.Users.Add(_teamStorageManager.GetUser(userId));
            }

            return _teamStorageManager.CreateTeam(teamToAdd);
        }
示例#2
0
 public StudyDto(Study study)
 {
     Id = study.ID;
     Name = study.Name;
     Stages = study.Stages.Select(s => new StageDto(s)).ToArray();
     Team = new TeamDto(study.Team);
     Items = new byte[] {};
     IsFinished = study.IsFinished;
 }
        public StudyDto CreaStudyDto()
        {
            var teamDto = new TeamDto
            {
                Id = 1
            };

            var criteria1 = new CriteriaDto
            {
                Name = "Name1",
                Rule = CriteriaDto.CriteriaRule.SmallerThan,
                DataMatch = new[] {"2000"},
                DataType = DataFieldDto.DataType.String,
                Description = "Check if the year is before 2000"
            };

            var criteria2 = new CriteriaDto
            {
                Name = "Is about...",
                DataType = DataFieldDto.DataType.Boolean,
                Rule = CriteriaDto.CriteriaRule.Equals,
                DataMatch = new[] {"true"},
                Description = "Check if the item is about snails."
            };

            var stage1 = new StageDto
            {
                Name = "stage1",
                Criteria = criteria1,
                DistributionRule = StageDto.Distribution.HundredPercentOverlap,
                ReviewerIDs = new[] {1, 2},
                ValidatorIDs = new[] {3},
                VisibleFields = new[] {StageDto.FieldType.Title, StageDto.FieldType.Author}
            };

            var stage2 = new StageDto
            {
                Name = "stage2",
                Criteria = criteria2,
                DistributionRule = StageDto.Distribution.HundredPercentOverlap,
                ReviewerIDs = new[] {3, 2},
                ValidatorIDs = new[] {4},
                VisibleFields = new[] {StageDto.FieldType.Title, StageDto.FieldType.Author}
            };

            var studyDto = new StudyDto
            {
                Name = "testStudy",
                Team = teamDto,
                Items = Resources.bibtex,
                Stages = new[] {stage1, stage2}
            };

            return studyDto;
        }
示例#4
0
        /// <summary>
        /// Update a team in the repository  with a new teamDTO
        /// Convert the teamDTO to a team
        /// </summary>
        /// <param name="teamId">Id of the team to be updated</param>
        /// <param name="newTeamDto"> DTO of what the team needs to be updated with</param>
        /// <returns></returns>
        public bool UpdateTeam(int teamId, TeamDto newTeamDto)
        {
            try
            {
                var teamToUpdate = _teamStorageManager.GetTeam(teamId);
                if (teamToUpdate == null)
                {
                    throw new NullReferenceException("Team Doesn't exist in database");
                }
                if (newTeamDto.UserIDs.Length == 0)
                {
                    throw new ArgumentException("You can't add or delete users from a team, only change its name");
                }
                if (!teamToUpdate.Users.Any())
                {
                    throw new ArgumentException("Team can't exist without users");
                }
                var teamToUpdateArray = teamToUpdate.Users.Select(u => u.ID).ToArray();
                var newTeamArray = newTeamDto.UserIDs;
                for (var i = 0; i < teamToUpdate.Users.Count; i++)
                {
                    if (teamToUpdateArray[i] == newTeamArray[i])
                    {
                    }
                    else
                    {
                        throw new ArgumentException("You can't add or delete users from a team, only change its name");
                    }
                }

                teamToUpdate.Users.Clear();
                teamToUpdate.Name = newTeamDto.Name;

                foreach (var userId in newTeamDto.UserIDs)
                {
                    try
                    {
                        teamToUpdate.Users.Add(_teamStorageManager.GetUser(userId));
                    }
                    catch (NullReferenceException)
                    {
                        throw new NullReferenceException("User can't be added to team, because user does not exist");
                    }
                }
                return _teamStorageManager.UpdateTeam(teamToUpdate);
            }
            catch (NullReferenceException)
            {
                throw new NullReferenceException("team does not exist");
            }
        }
        public void TestIntegrationTeamManagerCreateTeamUserNotInDB()
        {
            var team = new TeamDto() { Name = "team", UserIDs = new []{100}};

            _teamManager.CreateTeam(team);
        }
        public void TestIntegrationTeamManagerCreateTeamNoUsers()
        {
            var team = new TeamDto() { Name = "team"};

            _teamManager.CreateTeam(team);
        }