public int saveMatchup(Matchup matchup, List <MatchupRespons> matchupResponses, List <MatchupComment> matchupComments) { using (TransactionScope scope = new TransactionScope()) { var existingMatchup = db.Matchups.SingleOrDefault(x => x.MatchupId == matchup.MatchupId); if (existingMatchup == null) { db.Matchups.Add(matchup); } else if (existingMatchup != null && matchup.PatchVersion != ConfigurationManager.AppSettings["PatchVersion"]) { int result2 = SaveAsDuplicateMatchupWithActualPatch(existingMatchup, matchupResponses, matchupComments); if (result2 > 0) { scope.Complete(); } return(result2); } else { db.Entry(existingMatchup).CurrentValues.SetValues(matchup); } db.MatchupResponses.AddRange(matchupResponses); db.MatchupComments.AddRange(matchupComments); int result = db.SaveChanges(); scope.Complete(); return(result); } }
public Matchup DuplicateWithNewIds(Matchup matchup, Guid newMatchupId, Guid newMatchupResponsId) { var newMatchup = new Matchup(); newMatchup.AllyTop = matchup.AllyTop; newMatchup.AllyJungle = matchup.AllyJungle; newMatchup.AllyMid = matchup.AllyMid; newMatchup.AllyAdc = matchup.AllyAdc; newMatchup.AllySupport = matchup.AllySupport; newMatchup.EnemyTop = matchup.EnemyTop; newMatchup.EnemyJungle = matchup.EnemyJungle; newMatchup.EnemyMid = matchup.EnemyMid; newMatchup.EnemyAdc = matchup.EnemyAdc; newMatchup.EnemySupport = matchup.EnemySupport; newMatchup.PlayerId = matchup.PlayerId; newMatchup.CreationDate = DateTime.Now; newMatchup.CreationDate = DateTime.Now; newMatchup.PatchVersion = matchup.PatchVersion; if (String.IsNullOrEmpty(matchup.PatchVersion) || newMatchup.PatchVersion != ConfigurationManager.AppSettings["PatchVersion"]) { newMatchup.PatchVersion = ConfigurationManager.AppSettings["PatchVersion"]; } newMatchup.MatchupResponseId = newMatchupResponsId; newMatchup.MatchupId = newMatchupId; return(newMatchup); }
public int SaveAsDuplicateMatchupWithActualPatch(Matchup matchup, List <MatchupRespons> matchupResponses, List <MatchupComment> matchupComments) { int result = -1; var newMatchupid = Guid.NewGuid(); using (TransactionScope scope = new TransactionScope()) { //on matchup en changeant l'ID matchup.CreationDate = DateTime.Now; //on cherche le matchupResponses et on le duplique aussi en changeant l'ID var oldMatchupResponsId = matchup.MatchupResponseId; var newMatchupResponsId = Guid.NewGuid(); if (matchupResponses?.Count() > 0) { foreach (var item in matchupResponses) { db.MatchupResponses.Add(new MatchupRespons() { ChampionId = item.ChampionId, CreationDate = DateTime.Now, MatchupResponseId = newMatchupResponsId }); } } //on duplique les commentaires if (matchupComments?.Count() > 0) { foreach (var item in matchupComments) { db.MatchupComments.Add(new MatchupComment() { ChampionId = item.ChampionId, CreationDate = DateTime.Now, MatchupCommentId = Guid.NewGuid(), CommentText = item.CommentText, MatchupId = newMatchupid }); } } var newMatchup = matchup.DuplicateWithNewIds(matchup, newMatchupid, newMatchupResponsId); bool isExist = new DALCalculation().isPerfectMatchupExist(newMatchup); if (!isExist) { db.Matchups.Add(newMatchup); result = db.SaveChanges(); } scope.Complete(); } return(result); }
public int AddMatchup(MatchupInfos matchupInfos) { int result = -1; Matchup matchup = buildMatchupEntity(matchupInfos); List <MatchupRespons> matchupResponses = buildMatchupResponsEntity(matchupInfos, matchup.MatchupResponseId); List <MatchupComment> matchupComments = buildMatchupCommentsEntity(matchupInfos, matchup); if (matchup.MatchupId != Guid.Empty) { result = saveMatchup(matchup, matchupResponses, matchupComments); } return(result); }
public Guid createNewMatchup(Guid playerId, MatchupInfos matchupInfos) { Matchup matchup = buildMatchupEntity(matchupInfos); List <MatchupRespons> matchupResponses = buildMatchupResponsEntity(matchupInfos, matchup.MatchupResponseId); matchup.PlayerId = playerId; using (TransactionScope scope = new TransactionScope()) { db.Matchups.Add(matchup); db.MatchupResponses.AddRange(matchupResponses); db.SaveChanges(); scope.Complete(); return(matchup.MatchupId); } }
public Matchup buildMatchupEntity(MatchupInfos matchupInfos) { Matchup matchup = new Matchup(); matchup.AllyTop = matchupInfos.AllyTop; matchup.AllyJungle = matchupInfos.AllyJungle; matchup.AllyMid = matchupInfos.AllyMid; matchup.AllyAdc = matchupInfos.AllyAdc; matchup.AllySupport = matchupInfos.AllySupport; matchup.EnemyTop = matchupInfos.EnemyTop; matchup.EnemyJungle = matchupInfos.EnemyJungle; matchup.EnemyMid = matchupInfos.EnemyMid; matchup.EnemyAdc = matchupInfos.EnemyAdc; matchup.EnemySupport = matchupInfos.EnemySupport; if (matchupInfos.MatchupId == Guid.Empty) { matchup.MatchupId = Guid.NewGuid(); } else { matchup.MatchupId = matchupInfos.MatchupId; } matchup.PlayerId = matchupInfos.PlayerId; if (matchupInfos.MatchupResponseId == Guid.Empty) { matchup.MatchupResponseId = Guid.NewGuid(); } else { matchup.MatchupResponseId = matchupInfos.MatchupResponseId; } matchup.CreationDate = DateTime.Now; matchup.PatchVersion = matchupInfos.PatchVersion; if (String.IsNullOrEmpty(matchupInfos.PatchVersion)) { matchup.PatchVersion = ConfigurationManager.AppSettings["PatchVersion"]; } return(matchup); }
public bool isPerfectMatchupExist(Matchup matchup) { var listMatchup = db.Matchups.Where(x => x.PlayerId == matchup.PlayerId); listMatchup = listMatchup.Where(x => x.AllyTop == matchup.AllyTop); listMatchup = listMatchup.Where(x => x.AllyJungle == matchup.AllyJungle); listMatchup = listMatchup.Where(x => x.AllyMid == matchup.AllyMid); listMatchup = listMatchup.Where(x => x.AllyAdc == matchup.AllyAdc); listMatchup = listMatchup.Where(x => x.AllySupport == matchup.AllySupport); listMatchup = listMatchup.Where(x => x.EnemyTop == matchup.EnemyTop); listMatchup = listMatchup.Where(x => x.EnemyJungle == matchup.EnemyJungle); listMatchup = listMatchup.Where(x => x.EnemyMid == matchup.EnemyMid); listMatchup = listMatchup.Where(x => x.EnemyAdc == matchup.EnemyAdc); listMatchup = listMatchup.Where(x => x.EnemySupport == matchup.EnemySupport); listMatchup = listMatchup.Where(x => x.PatchVersion == matchup.PatchVersion); if (listMatchup.Count() > 0) { return(true); } return(false); }
public List <MatchupComment> buildMatchupCommentsEntity(MatchupInfos matchupInfos, Matchup matchup) { List <MatchupComment> matchupComments = new List <MatchupComment>(); if (matchupInfos.Answers?.Count > 0) { foreach (var comment in matchupInfos.Answers) { //var existingmatchupComment = db.MatchupComments.Where(x => x.MatchupId == matchupInfos.matchupId && x.ChampionId == comment.Id); MatchupComment matchupComment = new MatchupComment(); matchupComment.ChampionId = comment.ChampionId; matchupComment.CommentText = comment.Comments; matchupComment.PlayerId = matchup.PlayerId; matchupComment.MatchupCommentId = Guid.NewGuid(); matchupComment.CreationDate = DateTime.Now; matchupComment.MatchupId = matchup.MatchupId; matchupComments.Add(matchupComment); } } return(matchupComments); }