public bool DeleteTeam(Team team) { //intialize boolean that indicates if method succeeded to false bool success = false; //search database to ensure that the team already exists in the database Data.Entities.Team x = _db.Team.Where(a => a.Teamname.Equals(team.teamname)).FirstOrDefault(); //if the team does exist, remove the team from the database, but first, delete the userteams associated with it if (x != null) { IEnumerable <Data.Entities.UserTeam> y = x.UserTeam; if (y != null) { foreach (var item in y) { _db.UserTeam.Remove(item); } _db.SaveChanges(); } } if (x != null) { _db.Team.Remove(x); _db.SaveChanges(); //set boolean to true to indicate that we successfully added a team success = true; } return(success); }
public bool UpdateTeam(Team team) { bool success = true; int i = 0; //index for loops //first determine the ID of the team that we are updating Data.Entities.Team DBTeam = _db.Team.Where(z => z.Teamname.Equals(team.teamname)).FirstOrDefault(); //ensure that our DBteam is not null, we have an equal number of roles and users, and that we have more than 0 roles if (DBTeam != null && team.Roles.Count == team.Userlist.Count && team.Roles.Count > 0) { int DBTeamID = DBTeam.Id; //next, determine the elements in the USERTEAM table that have that teams ID List <Data.Entities.UserTeam> DBUserTeam = _db.UserTeam.Where(p => p.Teamid == DBTeamID).ToList(); //now, remove those elements from the userteam table if (DBUserTeam.Count > 0) { foreach (var item in DBUserTeam) { _db.UserTeam.Remove(item); } } //now, I want to add the elements from this team into the userteam table List <User> DomainUser = team.Userlist; List <bool> DomainRole = team.Roles; for (i = 0; i < DomainUser.Count; i++) { //determine the ID for each individual user in the team Data.Entities.User DBUser = _db.User.Where(z => z.Username.Equals(DomainUser[i].username)).FirstOrDefault(); if (DBUser == null) { //if the user didnt exist, we want to stop the program and return false success = false; return(success); } else { //here we add each user into the userteam table Data.Entities.UserTeam userteam = new Data.Entities.UserTeam(); userteam.Teamid = DBTeamID; userteam.Leader = DomainRole[i]; userteam.Userid = DBUser.Id; _db.UserTeam.Add(userteam); _db.SaveChanges(); } } } else { success = false; return(success); } return(success); }
public void DataToDomainTest() { //Arrange Data.Entities.Sides sideA = new Data.Entities.Sides(); Data.Entities.Team teamA = new Data.Entities.Team(); teamA.Teamname = "Good"; teamA.Id = 4; sideA.Team = teamA; sideA.Winreport = true; Data.Entities.Sides sideB = new Data.Entities.Sides(); Data.Entities.Team teamB = new Data.Entities.Team(); teamB.Teamname = "Bad"; teamB.Id = 7; sideB.Team = teamB; Data.Entities.Sides sideC = new Data.Entities.Sides(); Data.Entities.Challenge ch1 = new Data.Entities.Challenge(); ch1.Sides.Add(sideA); ch1.Sides.Add(sideB); ch1.GameModeId = 3; Data.Entities.Challenge ch2 = new Data.Entities.Challenge(); ch2.Sides.Add(sideA); ch2.Sides.Add(sideB); ch2.Id = 5; ch2.GameModeId = 4; Data.Entities.Challenge ch3 = new Data.Entities.Challenge(); ch3.Sides.Add(sideA); ch3.Sides.Add(sideB); ch3.Sides.Add(sideC); Data.Entities.Challenge ch4 = new Data.Entities.Challenge(); //Act Domain.Challenge r1 = Mapper.Map(ch1); Domain.Challenge r2 = Mapper.Map(ch2); Domain.Challenge r3 = Mapper.Map(ch3); Domain.Challenge r4 = Mapper.Map(ch4); //Arrange Assert.AreEqual(0, r1.id); Assert.AreEqual("Good", r1.Team1.teamname); Assert.AreEqual("Bad", r1.Team2.teamname); Assert.AreEqual(4, r1.Team1.id); Assert.AreEqual(7, r1.Team2.id); Assert.AreEqual(3, r1.GameModeId); Assert.AreEqual(5, r2.id); Assert.IsNull(r3); Assert.IsNull(r4); }
public void teammapperdmtest() { string team1name = "akashteam"; Data.Entities.Team team1 = new Data.Entities.Team(); team1.Teamname = team1name; team1.Id = 35; var dmteam1 = Mapper.Map(team1); Assert.AreEqual(dmteam1.teamname, team1name); Assert.AreEqual(dmteam1.id, team1.Id); }
public bool AddTeam(Team team) { //intialize boolean that indicates if method succeeded to false bool success = false; //search database to see if the team already exists in the database Data.Entities.Team x = _db.Team.Where(a => a.Teamname.Equals(team.teamname)).FirstOrDefault(); //if the team does not exist, add the team to the database if (x == null) { _db.Team.Add(Mapper.Map(team)); //set boolean to true to indicate that we successfully added a team _db.SaveChanges(); success = true; } //now, we need to add its userteams //now, I want to add the elements from this team into the userteam table List <User> DomainUser = team.Userlist; List <bool> DomainRole = team.Roles; //reobtain the current team from the database to obtain its ID Data.Entities.Team DBteam = _db.Team.Where(a => a.Teamname.Equals(team.teamname)).FirstOrDefault(); for (int i = 0; i < DomainUser.Count; i++) { //determine the ID for each individual user in the team Data.Entities.User DBUser = _db.User.Where(z => z.Username.Equals(DomainUser[i])).FirstOrDefault(); if (DBUser == null) { //if the user didnt exist, we do not add any userteams } else { //here we add each user into the userteam table Data.Entities.UserTeam userteam = new Data.Entities.UserTeam(); userteam.Teamid = DBteam.Id; userteam.Leader = DomainRole[i]; userteam.Userid = DBUser.Id; _db.UserTeam.Add(userteam); _db.SaveChanges(); } } return(success); }
public static Domain.Team Map(Data.Entities.Team deTeam) { Domain.Team dmTeam = new Domain.Team(); dmTeam.id = deTeam.Id; dmTeam.teamname = deTeam.Teamname; int i = 0; foreach (var item in deTeam.UserTeam) { dmTeam.Roles.Add(item.Leader); dmTeam.Userlist.Add(Map(item.User)); i += 1; } foreach (var item in deTeam.Rank) { dmTeam.rank.Add(item.Rank1); } return(dmTeam); }
public Team GetByTeamName(string teamname) { Team something = new Team(); //initialize team object! //get team id from the name if (teamname == null) { return(null); } Data.Entities.Team deteam = _db.Team.Where(h => h.Teamname.Equals(teamname)).Include("UserTeam.User").FirstOrDefault(); if (deteam != null) { something = Mapper.Map(deteam); } else { return(null); } return(something); }