Пример #1
0
 public TeamWindow(ViewModel.TeamView team, ViewModel.SPMSViewModel viewModel)
 {
     InitializeComponent();
     _team = team;
     _viewModel = viewModel;
 }
Пример #2
0
        /// <summary>
        /// Moves a user to a given team
        /// </summary>
        /// <param name="user">The user to change</param>
        /// <param name="team">The team to which to move the user</param>
        /// <returns>True if moving the user succeeds, false otherwise</returns>
        public bool MoveUserToTeam(UserView user, TeamView team)
        {
            if (!_isLoggedIn)
            {
                throw new InvalidOperationException("User must be logged in");
            }
            if (user == null || team == null)
            {
                throw new ArgumentNullException("Arguments to ChangeTeam must not be null");
            }

            bool result = _dataModel.MoveUserToTeam(user.UserID, team.TeamID);

            if (result && user.UserID == CurrUser.UserID)
            {
                CurrTeam = team;
                updateProjectsForUser();
            }

            return result;
        }
Пример #3
0
        /// <summary>
        /// Checks if user input for a project is valid
        /// </summary>
        /// <param name="name">The name of the project</param>
        /// <param name="startDate">The start date of the project</param>
        /// <param name="endDate">The end date of the project</param>
        /// <param name="owner">The owner of the project</param>
        /// <param name="team">The team responsible for the project</param>
        /// <returns>True if the data is valid, false otherwise</returns>
        public bool ValidateProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team)
        {
            bool result = true;

            result &= (name != null && name.Length > 0 && name.Length <= 50); // Name between 1 and 50 characters
            result &= startDate.HasValue; // Start date is required
            if (startDate.HasValue && endDate.HasValue)
            {
                result &= (startDate.Value < endDate.Value); // Sprint must start before it ends
            }
            result &= (owner != null); // Owner is required
            result &= (team != null); // Team is required

            return result;
        }
Пример #4
0
        /// <summary>
        /// Gets a list of users in a team and a list of users not in a team
        /// </summary>
        /// <param name="team">The team for which to search</param>
        /// <returns>A tuple, the first element of which is the list of team members and the second is the list of Users not in the team</returns>
        public Tuple<ObservableCollection<UserView>, ObservableCollection<UserView>> GetTeamMembers(TeamView team)
        {
            if (!_isLoggedIn)
            {
                throw new InvalidOperationException("User must be logged in");
            }
            else if (team == null) // Bad value
            {
                throw new ArgumentNullException("Arguments to GetTeamMembers must not be null");
            }

            var result = new Tuple<ObservableCollection<UserView>, ObservableCollection<UserView>>(
                new ObservableCollection<UserView>(),
                new ObservableCollection<UserView>());

            IEnumerable<User> members = _dataModel.GetTeamMembers(team.TeamID);
            IEnumerable<User> nonMembers = _dataModel.GetUsersNotInTeam(team.TeamID);

            if (members != null) // An error occurred
            {
                foreach (User u in members)
                {
                    result.Item1.Add(new UserView(u));
                }
            }

            if (nonMembers != null) // An error occurred
            {
                foreach (User u in nonMembers)
                {
                    result.Item2.Add(new UserView(u));
                }
            }

            return result;
        }
Пример #5
0
        /// <summary>
        /// Creates a new project
        /// </summary>
        /// <param name="name">The name of the project</param>
        /// <param name="startDate">The start date of the project</param>
        /// <param name="endDate">The end date of the project</param>
        /// <param name="owner">The User who owns the new project</param>
        /// <param name="team">The team responsible for the new project</param>
        /// <returns>True if creating the project succeeds, false otherwise</returns>
        public bool CreateProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team)
        {
            if (!_isLoggedIn)
            {
                throw new InvalidOperationException("User must be logged in");
            }
            else if (name == null || owner == null || team == null || !startDate.HasValue)
            {
                throw new ArgumentNullException("Arguments to AddProject must not be null");
            }

            bool result = _dataModel.CreateProject(name, startDate.Value, endDate, owner.UserID, team.TeamID);
            updateProjectsForUser();

            return result;
        }
Пример #6
0
        /// <summary>
        /// Updates the current project
        /// </summary>
        /// <param name="name">The name of the project</param>
        /// <param name="startDate">The start date of the project</param>
        /// <param name="endDate">The end date of the project</param>
        /// <param name="owner">The User who owns the new project</param>
        /// <param name="team">The team responsible for the new project</param>
        /// <returns>True if the changes succeed, false otherwise</returns>
        public bool ChangeCurrProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team)
        {
            if (!_isLoggedIn || CurrProject == null)
            {
                throw new InvalidOperationException("User must be logged in");
            }
            else if (name == null || !startDate.HasValue || owner == null || team == null)
            {
                throw new ArgumentNullException("Arguments to AddProject must not be null");
            }

            bool result = _dataModel.ChangeProject(CurrProject.ProjectID, name, startDate.Value, endDate, owner.UserID, team.TeamID);
            if (result)
            {
                updateProjectsForUser();
                CurrProject = new ProjectView(_dataModel.GetProjectByID(CurrProject.ProjectID));
            }

            return result;
        }
Пример #7
0
        /// <summary>
        /// Authenticates the user
        /// </summary>
        /// <param name="userId">The ID of the user to authenticate</param>
        /// <param name="password">The user's password</param>
        /// <returns>True if authentication succeeds, false otherwise</returns>
        public bool AuthenticateUser(int userId, string password)
        {
            string passHash = hashPassword(password);

            User curr = _dataModel.AuthenticateUser(userId, passHash);

            if (curr == null) //  Authentication failed
            {
                return false;
            }

            _isLoggedIn = true;

            CurrTeam = new TeamView(curr.Team_); // Store the team
            CurrUser = new UserView(curr); // Store the user

            IsManager = CurrUser.Role == UserRole.Manager;

            return true;
        }
        public void GetTeamByIDTest()
        {
            int teamId = -1;
            TeamView expected = new TeamView(target._dataModel.GetTeamByID(1));
            TeamView actual;
            target._isLoggedIn = false;
            try
            {
                actual = target.GetTeamByID(teamId);
                Assert.Fail("Exception not thrown");
            }
            catch (InvalidOperationException)
            {
                ;
            }

            target._isLoggedIn = true;
            try
            {
                actual = target.GetTeamByID(teamId);
                Assert.Fail("Exception not thrown");
            }
            catch (ArgumentOutOfRangeException)
            {
                ;
            }

            teamId = 1;
            actual = target.GetTeamByID(teamId);
            Assert.AreEqual(expected, actual);

            (target._dataModel as MockDataModel).failureOn = true;
            actual = target.GetTeamByID(teamId);
            Assert.IsNull(actual);
        }