public User[] GetAllUsersInsideTeam(Team team)
        {
            if(!team.ManagerReference.IsLoaded) team.ManagerReference.Load();
            var users = new List<User> {team.Manager};

            foreach (var workshop in team.Workshops)
            {
                users.AddRange(GetAllUsersInsideWorkshop(workshop));
            }

            return users.ToArray();
        }
 public TeamEntityViewModel MapToViewModel(Team model)
 {
     var viewModel = new TeamEntityViewModel();
     if (model != null)
     {
         viewModel.Id = model.TeamID;
         viewModel.Name = model.Name;
         if(model.Manager!=null)
         {
             viewModel.ManagerId = model.Manager.UserID;
             viewModel.ManagerName = model.Manager.Fullname;
         }
         else
         {
             viewModel.ManagerId = null;
             viewModel.ManagerName = string.Empty;
         }
     }
     return viewModel;
 }
 public void MapToModel(TeamEntityViewModel entityViewModel, Team model, bool mapManager)
 {
     model.Name = entityViewModel.Name;
     if(mapManager) model.Manager = _userRepository.GetByID((int)entityViewModel.ManagerId);
 }
 public void MapToModel(TeamEntityViewModel entityViewModel, Team model)
 {
     MapToModel(entityViewModel, model, true);
 }
        private void SaveAndCreateManager(TeamEntityViewModel teamEntityViewModel)
        {
            _teamValidator.EntityViewModel = teamEntityViewModel;
            var managerViewModel = teamEntityViewModel.ManagerEntityViewModel;
            _userValidator.EntityViewModel = managerViewModel;
            bool isTeamValid = _teamValidator.IsInsertValid();
            bool isUserValid = _userValidator.IsInsertValid();
            bool isValid = isTeamValid && isUserValid;
            if(isValid)
            {
                var teamManager = new User();
                _userMapper.MapToModel(managerViewModel, teamManager);

                var team = new Team();
                _teamMapper.MapToModel(teamEntityViewModel, team, false);

                teamManager.UserLevel = (int) UserLevels.TeamManager;
                teamManager.ManagesTeam = team;
                team.Manager = teamManager;

                _teamRepository.Add(team);
                _teamRepository.Save();
            }
            else throw new ValidationException();
        }
        private void SaveAndSelectManager(TeamEntityViewModel teamEntityViewModel)
        {
            _teamValidator.EntityViewModel = teamEntityViewModel;
            if(_teamValidator.IsInsertValid())
            {
                var team = new Team();
                _teamMapper.MapToModel(teamEntityViewModel, team);

                team.Manager.UserLevel = (int) UserLevels.TeamManager;
                team.Manager.ManagesTeam = team;

                _teamRepository.Add(team);
                _teamRepository.Save();
            }
            else throw new ValidationException();
        }
        public Document[] GetPublicDocumentsByTeam(User currentUser, Team team)
        {
            var teamUsers = _administrationService.GetAllUsersInsideTeam(team);
            var currentUserTeam = _userService.GetUserTeam(currentUser);
            var documents = new List<Document>();
            foreach (var user in teamUsers)
            {
                Func<Document, bool> documentSelectionCondition;
                if(currentUserTeam.TeamID == team.TeamID)
                {
                    documentSelectionCondition = (d => d.DistributionMode == DocumentDitributionMode.Public.ID ||
                                                         d.DistributionMode == DocumentDitributionMode.Team.ID);
                }
                else
                {
                    documentSelectionCondition = (d => d.DistributionMode == DocumentDitributionMode.Public.ID);
                }

                if(!user.DocumentsAuthored.IsLoaded) user.DocumentsAuthored.Load();
                documents.AddRange(user.DocumentsAuthored.Where(documentSelectionCondition).ToArray());
            }

            return documents.ToArray();
        }