Ejemplo n.º 1
0
        public async Task <IActionResult> AddTeamToProject([FromBody] ProjectTeamModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsProject project = _repository.GetProjectbyProjectName(model.ProjectName);
                if (project == null)
                {
                    return(BadRequest("Cannot find the Project"));
                }

                CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);
                if (team == null)
                {
                    return(BadRequest("Cannot find the Team"));
                }


                if (project.ProjectTeams.Where(t => t.TeamId == team.TeamId).Count() > 0)
                {
                    return(BadRequest("Team has already been added for the Project"));
                }

                project.ProjectTeams.Add(new ProjectTeam
                {
                    ProjectId = project.ProjectId,
                    TeamId    = team.TeamId
                });
                _repository.Save();
                return(Ok("Team has been added for Project"));
            }
            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteUserFromTeam([FromBody] TeamUserModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsUser user = await _userManager.FindByNameAsync(model.UserName);

                if (user == null)
                {
                    return(BadRequest("Cannot Find the User"));
                }

                CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);

                if (team == null)
                {
                    return(BadRequest("Cannot Find the Team"));
                }
                else
                {
                    TeamUser teamuser = team.TeamUsers.Where(t => t.UserId == user.Id).FirstOrDefault();
                    if (teamuser == null)
                    {
                        return(BadRequest("User not in the Team"));
                    }
                    else
                    {
                        team.TeamUsers.Remove(teamuser);
                        _repository.Save();
                    }
                }
                return(Ok("User has been removed from Team"));
            }
            return(BadRequest());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteTeamFromProject([FromBody] ProjectTeamModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsProject project = _repository.GetProjectbyProjectName(model.ProjectName);
                if (project == null)
                {
                    return(BadRequest("Cannot find the Project"));
                }

                CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);
                if (team == null)
                {
                    return(BadRequest("Cannot find the Team"));
                }

                ProjectTeam pt = project.ProjectTeams.Where(p => p.TeamId == team.TeamId).FirstOrDefault();

                if (pt == null)
                {
                    return(BadRequest("Team is not assigned to the Project"));
                }

                project.ProjectTeams.Remove(pt);
                _repository.Save();
                return(Ok("Team has been deleted from Project"));
            }
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddUserToTeam([FromBody] TeamUserModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);
                if (team == null)
                {
                    return(BadRequest("Cannot Find the Team"));
                }
                else
                {
                    CoalyticsUser user = await _userManager.FindByNameAsync(model.UserName);

                    if (user == null)
                    {
                        return(BadRequest("Cannot Find the User"));
                    }
                    else if (team.TeamUsers.Where(u => u.UserId == user.Id).Count() > 0)
                    {
                        return(BadRequest("User already in Team"));
                    }
                    else
                    {
                        team.TeamUsers.Add(new TeamUser()
                        {
                            TeamId = team.TeamId,
                            UserId = user.Id
                        });
                        _repository.Save();
                    }
                }
                return(Ok("User has been added into Team"));
            }
            return(BadRequest());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete Existing Team
        /// </summary>
        /// <param name="teamName"></param>
        public void DeleteTeam(string teamName)
        {
            CoalyticsTeam team = GetTeambyTeamName(teamName);

            if (team != null)
            {
                _dbContext.CoalyticsTeams.Remove(team);
                Save();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a New Team
        /// </summary>
        /// <param name="teamName"></param>
        public void AddTeam(string teamName)
        {
            CoalyticsTeam team = GetTeambyTeamName(teamName);

            if (team == null)
            {
                _dbContext.CoalyticsTeams.Add(new CoalyticsTeam()
                {
                    TeamName = teamName,
                    TeamId   = Guid.NewGuid().ToString()
                });
                Save();
            }
        }
Ejemplo n.º 7
0
 public async Task <IActionResult> GetTeamProjects([FromBody] CoalyticsTeamModel model)
 {
     if (ModelState.IsValid)
     {
         CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);
         if (team == null)
         {
             return(BadRequest("Cannot Find the Team"));
         }
         else
         {
             return(Ok(team.TeamProjects));
         }
     }
     return(BadRequest());
 }
Ejemplo n.º 8
0
 public async Task <IActionResult> DeleteTeam([FromBody] CoalyticsTeamModel model)
 {
     if (ModelState.IsValid)
     {
         CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);
         if (team == null)
         {
             return(BadRequest("Cannot Find the Team"));
         }
         else
         {
             if (team.TeamProjects.Count() > 0)
             {
                 return(BadRequest("Cannot Delete Team. There are projects assigned for this Team"));
             }
             else
             {
                 _repository.DeleteTeam(model.TeamName);
             }
         }
         return(Ok("Team has been Deleted"));
     }
     return(BadRequest());
 }