public bool UpdateTeam(string teamName, List <AllUserAndTeam> teamMembers) { try { using (Cafeteria_Vernier_dbEntities cvDatabase = new Cafeteria_Vernier_dbEntities()) { foreach (var existingMember in cvDatabase.TeamMembers.Where(x => x.Name.Equals(teamName))) { cvDatabase.TeamMembers.DeleteObject(existingMember); } foreach (AllUserAndTeam teamMember in teamMembers) { cvDatabase.AddToTeamMembers(new TeamMember { Name = teamName, UserID = teamMember.Name }); } cvDatabase.SaveChanges(); return(true); } } catch (Exception error) { throw new FaultException(error.Message); } }
public bool AddNewTeam(TeamInfo teamInfo, List <AllUserAndTeam> members) { try { using (Cafeteria_Vernier_dbEntities cvDatabase = new Cafeteria_Vernier_dbEntities()) { cvDatabase.AddToTeams(new Team { AdminName = teamInfo.TeamAdmin, JoinDate = teamInfo.EntryDate, Logo = teamInfo.TeamImage, Name = teamInfo.TeamD, TeamAccount = new TeamAccount { Minutes = 0, Name = teamInfo.TeamD, Status = false, EntryDate = DateTime.Today } }); foreach (AllUserAndTeam teamMember in members) { cvDatabase.AddToTeamMembers(new TeamMember { AutoInc = default(long), UserID = teamMember.Name, Name = teamInfo.TeamD }); } cvDatabase.SaveChanges(); } return(true); } catch (Exception) { throw new FaultException(ServiceVariables.ERROR_MESSAGES[0, 2]); } }