public User UpdateUserId(int userid, int matchid, User val) { var objuser = CommanClass.GetConnection().Users.Where(a => a.Id == userid).FirstOrDefault(); if (objuser == null) { CommanClass.GetConnection().Users.Add(val); } else { foreach (UserMatch item in val.UserMatches) { var usermatch = CommanClass.GetConnection().UserMatches.Where(a => a.UserId == userid && a.MatchId == matchid).FirstOrDefault(); if (usermatch == null) { // dbcontext.Users.Add(objuser); } else { CommanClass.GetConnection().UserMatches.Remove(usermatch); CommanClass.GetConnection().SaveChanges(); } } CommanClass.GetConnection().Users.Remove(objuser); CommanClass.GetConnection().SaveChanges(); CommanClass.GetConnection().Users.Add(val); } CommanClass.GetConnection().SaveChanges(); return(objuser); }
public IEnumerable <Contests> GettingContestId(int id) { //List<Contests> listcontest = new List<Contests>(); //var contests = CommanClass.GetConnection().ContestUsers.Where(a => a.Id == id).ToList(); //foreach (var item in contests[0].Contest.ContestUsers) //{ var contest = CommanClass.GetConnection().ContestUsers.Where(a => a.ContestId == id) // && a.UserId == item.UserId) .Select(t => new Contests { //username = t.User.FirstName + " " + t.User.LastName, //teamname = t.Team.TeamName, //players = t.Team.UserMatches.Where(b => b.TeamId == t.TeamId && b.UserId == t.UserId).Select(a => new PlayerEntity() //Where(b => b.TeamId == item.TeamId && b.UserId == item.UserId).Select(a => new PlayerEntity() // { // Id = a.Player.Id, // FirstName = a.Player.FirstName, // LastName = a.Player.LastName, // Age = a.Player.Age, // Address = a.Player.Address, // PlayerRoleName = a.Player.PlayerRole.Name, // playerimage = a.Player.ImagePath, // Points = a.Player.PlayerScores.Where(x => x.PlayerId.Value == a.PlayerId).FirstOrDefault().Points.Value, // Credits = a.Player.PlayerScores.Where(x => x.PlayerId.Value == a.PlayerId).FirstOrDefault().Credits //}) }).ToList(); return(contest); // listcontest.Add(contest); //} //return listcontest.ToList(); }
public int DeleteUserId(int userid, int matchid) { var objuser = CommanClass.GetConnection().Users.Where(a => a.Id == userid).FirstOrDefault(); if (objuser == null) { //dbcontext.Users.Add(val); return(0); } else { for (int i = 0; i <= 11; i++) { var usermatch = CommanClass.GetConnection().UserMatches.Where(a => a.UserId == userid && a.MatchId == matchid).FirstOrDefault(); if (usermatch == null) { // dbcontext.Users.Add(objuser); } else { CommanClass.GetConnection().UserMatches.Remove(usermatch); CommanClass.GetConnection().SaveChanges(); } } CommanClass.GetConnection().Users.Remove(objuser); CommanClass.GetConnection().SaveChanges(); // dbcontext.Users.Add(val); } return(1); }
public IEnumerable <PlayerEntity> GettingPlayerBasedOnTeamId(int userid, int matchid, int teamid) //IEnumerable<userplayer> { var player = AutoMapper.Mapper.Map <List <userplayer> >(CommanClass.GetConnection().UserMatches.Where(a => a.UserId == userid && a.MatchId == matchid && a.TeamId == teamid).ToList()); //foreach (var player in players) //{ // player.player.Id = player.player.Id; // player.player.FirstName = player.player.FirstName; // player.player.LastName = player.player.LastName; // player.player.Age = player.player.Age; // player.player.Address = player.player.Address; // player.player.PlayerRoleName = player.player.PlayerRoleName; // player.player.Points = player.player.PlayerScores.Where(ps => ps.PlayerId.Value == player.player.Id).FirstOrDefault().Points.Value; // player.player.Credits = player.player.PlayerScores.Where(ps => ps.PlayerId.Value == player.player.Id).FirstOrDefault().Credits; //} var players = player.Select(a => new PlayerEntity { Id = a.player.Id, FirstName = a.player.FirstName, LastName = a.player.LastName, Age = a.player.Age, Address = a.player.Address, PlayerRoleName = a.player.PlayerRoleName, Points = a.player.PlayerScores.Where(ps => ps.PlayerId.Value == a.player.Id).FirstOrDefault().Points.Value, Credits = a.player.PlayerScores.Where(ps => ps.PlayerId.Value == a.player.Id).FirstOrDefault().Credits }); return(players); }
public UserMatch CheckUserData(int id, int matchid) { UserMatch objuser = new UserMatch(); try { objuser = CommanClass.GetConnection().UserMatches.Where(a => a.UserId == id).Where(b => b.MatchId == matchid).FirstOrDefault(); } catch (Exception ex) { } return(objuser); }
public Users UserLogin(Login login) { //var objuser = AutoMapper.Mapper.Map<Login>(CommanClass.GetConnection().Users.Where(a => a.UserName == login.UserName && a.Password == login.Password).FirstOrDefault()); //return objuser; var Users = CommanClass.GetConnection().Users.Where(a => a.UserName == login.UserName && a.Password == login.Password) .Select(t => new Users { userid = t.Id, firstname = t.FirstName, lastname = t.LastName, username = t.UserName, emailaddress = t.EmailAddress, age = t.Age, Password = t.Password, RemeberMe = true, usercontests = t.ContestUsers.Where(uc => uc.UserId == t.Id).Select(cu => new UserContest() { contestid = cu.ContestId, Name = cu.Contest.Name }).ToList(), userMatches = t.UserMatches.Select(p => new UserMatchs { matchId = p.MatchId, matchName = p.Match.Name, matchTeams = t.UserMatches.Select(q => new MatchTeams { teamId = q.Team.Id, teamName = q.Team.TeamName, players = t.UserMatches.Where(pq => pq.UserId == t.Id && pq.MatchId == p.MatchId && pq.TeamId == q.TeamId).Select(pl => new FabricApplication.Models.BAL.players { playerid = pl.Player.Id, firstName = pl.Player.FirstName, lastName = pl.Player.LastName, age = pl.Player.Age, address = pl.Player.Address, playerRoleName = pl.Player.PlayerRole.Name, playerimage = pl.Player.ImagePath, Points = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Points.Value, Credits = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Credits }).ToList(), }).GroupBy(n => new { n.teamId, n.teamName }) .Select(g => g.FirstOrDefault()).ToList() }).GroupBy(n => new { n.matchId, n.matchName }) .Select(g => g.FirstOrDefault()).ToList() // Points = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Points.Value, // Credits = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Credits }).FirstOrDefault(); return(Users); }
//private readonly ServiceFabricEntities7 dbcontext; //public PlayerRespository() //{ // dbcontext = new ServiceFabricEntities7(); //} public Players GettingPlayerId(int id) { //var teams = dbcontext.Players.Where(a => a.Id == id) // .Select(t => new Players // { // PlayerId = t.Id, // FirstName = t.FirstName, // LastName = t.LastName, // Age = t.Age, // Address= t.Address, // MatchPlayers = t.MatchPlayers.Select(p => new FabricApplication.Models.DAL.MatchPlayer // { // Id = p.Id, // PlayerId = p.PlayerId, // MatchId = p.MatchId, // MatchName = p.Match.Name, // }) // }).ToList(); var players = AutoMapper.Mapper.Map <List <Players> >(CommanClass.GetConnection().Players.Where(a => a.Id == id).ToList()); return(players.FirstOrDefault()); }
public Users GettingUserId(int id) { //var teams = dbcontext.Users.Where(a => a.Id == id) // .Select(t => new user // { // Id = t.Id, // Firstname = t.FirstName, // Lastname = t.LastName, // age = t.Age, // Username = t.UserName // //, // //Emailid = t.EmailAddress // //, // //Userplayers = t.UsersPlayers.Select(p => new FabricApplication.Models.DAL.Userplayer // //{ // // Id = p.Id, // // //Playerid = p.PlayerId, // // //Userid = p.UserId, // // //PlayerName = p.Player.FirstName, // // //UserTeamid = p.UserTeamId, // // UserTeamName = p.UserTeam.TeamName // //}) // }).ToList(); // var Users = AutoMapper.Mapper.Map<List<user>>(CommanClass.GetConnection().Users.Where(a => a.Id == id).ToList()); var Users = CommanClass.GetConnection().Users.Where(a => a.Id == id) .Select(t => new Users { userid = t.Id, firstname = t.FirstName, lastname = t.LastName, username = t.UserName, emailaddress = t.EmailAddress, age = t.Age, Password = t.Password, RemeberMe = true, userMatches = t.UserMatches.Where(m => m.UserId == id).Select(p => new UserMatchs { matchId = p.MatchId, matchName = p.Match.Name, matchTeams = t.UserMatches.Select(q => new MatchTeams { teamId = q.Team.Id, teamName = q.Team.TeamName, players = t.UserMatches.Where(pq => pq.UserId == id && pq.MatchId == p.MatchId && pq.TeamId == q.TeamId).Select(pl => new FabricApplication.Models.BAL.players { playerid = pl.Player.Id, firstName = pl.Player.FirstName, lastName = pl.Player.LastName, age = pl.Player.Age, address = pl.Player.Address, playerRoleName = pl.Player.PlayerRole.Name }).ToList(), }).GroupBy(n => new { n.teamId, n.teamName }) .Select(g => g.FirstOrDefault()).ToList() }).GroupBy(n => new { n.matchId, n.matchName }) .Select(g => g.FirstOrDefault()).ToList() // Points = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Points.Value, // Credits = pl.Player.PlayerScores.Where(x => x.PlayerId.Value == pl.PlayerId).FirstOrDefault().Credits }).FirstOrDefault(); return(Users); }
public int GetMaxId() { var userid = CommanClass.GetConnection().Users.OrderByDescending(u => u.Id).FirstOrDefault(); return(userid.Id); }
public Matches UpdateUserMatch(int teamid, Matches val) { var objuser = CommanClass.GetConnection().UserMatches.Where(a => a.MatchId == val.Id && a.TeamId == teamid && a.UserId == val.UserId).FirstOrDefault(); if (objuser == null) { // CommanClass.GetConnection().Users.Add(val); } else { foreach (FabricApplication.Models.BAL.MatchPlayer item in val.MatchPlayers) { var userPlayerPoints = CommanClass.GetConnection().UserMatches.Where(a => a.PlayerId == item.PlayerId && a.MatchId == item.MatchId).FirstOrDefault(); if (objuser == null && userPlayerPoints == null) { // dbcontext.Users.Add(objuser); } else { using (var db = CommanClass.GetConnection()) { if (item.IsSelected == true) { UserMatch usermatch = new UserMatch() { Id = item.Id, UserId = val.UserId, MatchId = item.MatchId, PlayerId = item.PlayerId, TeamId = teamid }; db.UserMatches.Attach(usermatch); var usermatchs = db.Entry(usermatch); usermatchs.Property(x => x.MatchId).IsModified = true; usermatchs.Property(x => x.UserId).IsModified = true; usermatchs.Property(x => x.PlayerId).IsModified = true; usermatchs.Property(x => x.TeamId).IsModified = true; var PlayerscoreId = db.PlayerScores.AsNoTracking().Where(a => a.PlayerId == item.PlayerId && a.MatchId == item.MatchId).FirstOrDefault(); PlayerScore playerscore = new PlayerScore() { PlayerId = item.PlayerId, MatchId = item.MatchId, Id = PlayerscoreId.Id, Points = item.Points, Credits = item.Credits }; db.PlayerScores.Attach(playerscore); var playerscores = db.Entry(playerscore); playerscores.Property(x => x.PlayerId).IsModified = true; playerscores.Property(x => x.MatchId).IsModified = true; playerscores.Property(x => x.Points).IsModified = true; playerscores.Property(x => x.Credits).IsModified = true; db.SaveChanges(); } } } } } return(val); }
public IEnumerable <User> GettingUserId() { var Users = AutoMapper.Mapper.Map <List <User> >(CommanClass.GetConnection().Users.ToList()); return(Users); }
//private readonly ServiceFabricEntities7 dbcontext; //public MatchRespository() //{ // dbcontext = new ServiceFabricEntities7(); //} public Matches GettingMatchId(int id) { //var model = (from match in dbcontext.Matches // join matchPlayers in dbcontext.MatchPlayers on match.Id equals matchPlayers.MatchId // join player in dbcontext.Players on matchPlayers.PlayerId equals player.Id // join playerScores in dbcontext.PlayerScores on player.Id equals playerScores.PlayerId // join playerRole in dbcontext.PlayerRoles on player.RoleId equals playerRole.Id // where match.Id == id // select new Matches // { // Id = match.Id, // MatchName = match.Name, // Location = match.Location, // Date = match.Date, // PlayerId = player.Id, // FirstName = player.FirstName, // LastName = player.LastName, // Age = player.Age, // Address = player.Address, // Points = playerScores.Points, // PlayerRoleName = playerRole.Name // }).ToList(); //var teams = dbcontext.Matches.Where(a => a.Id == id) // .Select(t => new Matches // { // MatchId = t.Id, // MatchName = t.Name, // Location = t.Location, // Date = t.Date, // MatchPlayers = t.MatchPlayers.Select(p => new FabricApplication.Models.DAL.MatchPlayer // { // Id = p.Id, // PlayerId = p.PlayerId, // MatchId = p.MatchId, // PlayerFirstName = p.Player.FirstName, // PlayerLastName = p.Player.LastName // }), // PlayerScores = t.PlayerScores.Select(ps => new FabricApplication.Models.DAL.PlayerScore // { // Id = ps.Id, // MatchId = ps.PlayerId, // PlayerId = ps.PlayerId, // Points = ps.Points // }) // }).ToList(); var matches = CommanClass.GetConnection().Matches.Where(a => a.Id == id) .Select(t => new Matches { Id = t.Id, Name = t.Name, Location = t.Location, Date = t.Date, MatchPlayers = t.MatchPlayers.Select(p => new FabricApplication.Models.BAL.MatchPlayer { Id = p.Id, PlayerId = p.PlayerId, MatchId = p.MatchId, MatchName = p.Match.Name, FirstName = p.Player.FirstName, LastName = p.Player.LastName, PlayerImage = p.Player.ImagePath, Age = p.Player.Age, Address = p.Player.Address, PlayerRoleName = p.Player.PlayerRole.Name, IsSelected = false, Points = t.PlayerScores.Where(x => x.PlayerId.Value == p.PlayerId).FirstOrDefault().Points.Value, Credits = t.PlayerScores.Where(x => x.PlayerId.Value == p.PlayerId).FirstOrDefault().Credits.Value }) }).FirstOrDefault(); //var matches = AutoMapper.Mapper.Map<List<MatchEntity>>(CommanClass.GetConnection().Matches.Where(a => a.Id == id).ToList()); //foreach (var player in matches[0].MatchPlayers) //{ // player.player.Points = player.player.PlayerScores.Where(x => x.PlayerId.Value == player.player.Id).FirstOrDefault().Points.Value; // player.player.Credit = player.player.PlayerScores.Where(x => x.PlayerId.Value == player.player.Id).FirstOrDefault().Credits; //} //foreach (var MatchPlayers in matches[0].MatchPlayers) //{ // MatchPlayers.MatchId = MatchPlayers.MatchId; // MatchPlayers.MatchName = MatchPlayers.MatchName; // MatchPlayers.PlayerId = MatchPlayers.player.Id; // MatchPlayers.FirstName = MatchPlayers.player.FirstName; // MatchPlayers.LastName = MatchPlayers.player.LastName; // MatchPlayers.Address = MatchPlayers.player.Address; // MatchPlayers.Age = MatchPlayers.player.Age; // MatchPlayers.PlayerRoleName = MatchPlayers.player.PlayerRoleName; // MatchPlayers.Points = MatchPlayers.player.PlayerScores.Where(x => x.PlayerId.Value == MatchPlayers.player.Id).FirstOrDefault().Points.Value; // MatchPlayers.Credit = MatchPlayers.player.PlayerScores.Where(x => x.PlayerId.Value == MatchPlayers.player.Id).FirstOrDefault().Credits; //} return(matches); }
public int GetMaxMatchId() { var matchid = CommanClass.GetConnection().Matches.OrderByDescending(u => u.Id).FirstOrDefault(); return(matchid.Id); }
public IEnumerable <Matchs> GettingMatchId() { var matches = AutoMapper.Mapper.Map <List <Matchs> >(CommanClass.GetConnection().Matches.ToList()); return(matches); }
public IEnumerable <Players> GettingPlayerId() { var players = AutoMapper.Mapper.Map <List <Players> >(CommanClass.GetConnection().Players.ToList()); return(players); }