EnVisageOnline/Main/Source/PrevuWebAPI/Code/Managers/APITeamManager.cs

66 lines
2.0 KiB
C#

using EnVisage;
using EnVisage.Code.BLL;
using EnVisage.Models;
using PrevuWebAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrevuWebAPI.Code.Managers
{
public class APITeamManager : BaseManager
{
private TeamManager _manager = new TeamManager(PrevuEFContext.PrevuEntity);
public APIClientCallBackManager _callBackManager = new APIClientCallBackManager();
public List<APITeamModel> getTeamsForProject(Guid projectID)
{
List<APITeamModel> results = new List<APITeamModel>();
List<Team> teams=_manager.GetTeamsByProject(projectID).ToList<Team>();
foreach(Team m in teams)
{
results.Add(getAPIModel(m));
}
return results;
}
private APITeamModel getAPIModel(Team t)
{
return new APITeamModel()
{
TeamName = t.Name
};
}
public List<Guid> ValidateTeams(List<APITeamModel> teams)
{
if (teams == null)
teams = new List<APITeamModel>();
List<Guid> results = new List<Guid>();
foreach (APITeamModel team in teams)
{
var t = _manager.GetTeamByName(team.TeamName);
if (t == null || t.Id == Guid.Empty)
{
// if team does not exist check to see if its company name, and if so
//add all the teams for that company
GetTeamsByCompany(team.TeamName,ref results);
}else
results.Add(t.Id);
}
return results;
}
public void GetTeamsByCompany(string companyName, ref List<Guid> results)
{
var teams = _manager.GetTeamsByCompanyName(companyName);
foreach(Team t in teams)
{
results.Add(t.Id);
}
}
}
}