private EntityLinkProtocolViewModel GetEntityLinkProtocol(ProtocolRecord protocolRecord) { EntityLinkProtocolViewModel entityLink = null; if (protocolRecord.personId > 0) { entityLink = new EntityLinkProtocolViewModel(); entityLink.main = new EntityLinkViewModel() { id = protocolRecord.personId.ToString(), text = GetPersonName(protocolRecord.personId.Value), title = GetPersonName(protocolRecord.personId.Value) }; protocolModelUtils.CalculateMinutes(protocolRecord, entityLink); entityLink.info = GetEventName(protocolRecord.eventId); if (protocolRecord.CustomIntValue.HasValue) { entityLink.extra = new EntityLinkProtocolViewModel() { main = new EntityLinkViewModel() { id = protocolRecord.CustomIntValue.ToString(), text = GetPersonName(protocolRecord.CustomIntValue.Value), title = GetPersonName(protocolRecord.CustomIntValue.Value) } }; } } return(entityLink); }
public ProtocolRecordPersonInfo(Person person, ProtocolRecord protocolRecord) { this.person = person; this.protocolRecord = protocolRecord; protocolRecordInfo = new ProtocolRecordInfo(protocolRecord); }
private IEnumerable <Game> ApplySettings(IQueryable <Game> gamesQuery) { if (FillRounds) { gamesQuery = gamesQuery.Include(g => g.round); if (FillTourneys) { gamesQuery = gamesQuery.Include(g => g.round.tourney); } } if (FillTeams) { gamesQuery = gamesQuery.Include(g => g.home).Include(g => g.away); } if (FillStadiums) { gamesQuery = gamesQuery.Include(g => g.stadium); } // TODO: Check for one to multiple if (FillProtocols) { gamesQuery = gamesQuery.Include(t => t.ProtocolRecord); } IEnumerable <ProtocolRecord> protocols = new ProtocolRecord[0]; gamesQuery = gamesQuery.Take(LimitEntitiesSelections); IEnumerable <Game> games = gamesQuery.ToList(); //if (FillProtocols) //{ // var protocolRecordDal = new ProtocolRecordDal(); // var gameIds = new List<int>(); // gameIds.AddRange(games.Select(g => g.Id).Distinct()); // protocols = protocolRecordDal.GetProtocol(gameIds).ToList(); // foreach (Game game in games) // { // if (FillProtocols && protocols.Any()) // { // game.ProtocolRecord = protocols.Where(p => p.gameId == game.Id).ToList(); // } // else // { // game.ProtocolRecord = null; // } // } //} return(games); }
private bool CheckCriteria(string criteria, ProtocolRecord parentEntity) { string name = GetFieldFromCriteria(criteria); string value = GetValueFromCriteria(criteria); bool checkIsEqual = !criteria.Contains("!"); return(parentEntity._children.Any( t => t.Type.Name == name && (checkIsEqual ? t.Value == value : t.Value != value))); }
public void CalculateMinutes(ProtocolRecord record, EntityLinkProtocolViewModel model) { if (!record.ExtraTime) { model.minute = record.Minute; model.extraMinute = null; return; } model.minute = record.Minute.HasValue ? gameFormatManager.GetRoundTime(record.Minute.Value) : record.Minute; model.extraMinute = model.minute.HasValue ? record.Minute.Value - model.minute.Value : (int?)null; }
public IEnumerable <ProtocolRecord> GetReservePlayers(int teamId) { var reserveRecords = new List <ProtocolRecord>(); reserveRecords.AddRange(records .Where(r => r.ProtocolRecord.teamId == teamId && r.IsStartReserve) .Select(r => r.ProtocolRecord)); ProtocolRecord defaultStartReserve = ProtocolRecordInfo.CreateDefaultStartReserve(Game.Id, teamId); CompleteWithEmpty(reserveRecords, defaultStartReserve, PlayersReserveCount); return(reserveRecords); }
public IEnumerable <ProtocolRecord> GetMainPlayers(int teamId) { var mainRecords = new List <ProtocolRecord>(); mainRecords.AddRange(records .Where(r => r.ProtocolRecord.teamId == teamId && r.IsStartMain) .Select(r => r.ProtocolRecord)); ProtocolRecord defaultStartMain = ProtocolRecordInfo.CreateDefaultStartMain(Game.Id, teamId); CompleteWithEmpty(mainRecords, defaultStartMain, PlayersMainCount); return(mainRecords); }
public int SaveProtocol(int gameId, IEnumerable <ProtocolRecord> protocolRecords) { if (protocolRecords == null) { return(0); } List <ProtocolRecord> saveRecords = protocolRecords.ToList(); IEnumerable <int> saveIds = saveRecords.Select(pr => pr.Id); IEnumerable <ProtocolRecord> dbRecords = GetProtocol(gameId); if (dbRecords.Any()) { IEnumerable <int> dbIds = dbRecords.Select(r => r.Id); IEnumerable <int> removedIds = dbIds.Except(saveIds).ToList(); if (removedIds.Any()) { IEnumerable <ProtocolRecord> removeRecords = dbRecords.Where(pr => removedIds.Contains(pr.Id)); Context.RemoveRange(removeRecords); } IEnumerable <ProtocolRecord> updateRecords = dbRecords.Where(pr => saveIds.Contains(pr.Id)); if (updateRecords.Any()) { foreach (ProtocolRecord updateRecord in updateRecords) { ProtocolRecord saveRecord = saveRecords.First(pr => pr.Id == updateRecord.Id); updateRecord.gameId = saveRecord.gameId; updateRecord.teamId = saveRecord.teamId; updateRecord.personId = saveRecord.personId; updateRecord.eventId = saveRecord.eventId; updateRecord.Minute = saveRecord.Minute; updateRecord.CustomIntValue = saveRecord.CustomIntValue; updateRecord.ExtraTime = saveRecord.ExtraTime; } Context.UpdateRange(updateRecords); IEnumerable <int> updateIds = updateRecords.Select(pr => pr.Id); saveRecords.RemoveAll(pr => updateIds.Contains(pr.Id)); } } Context.AddRange(saveRecords); return(Context.SaveChanges()); }
public static ProtocolRecordViewModel ToViewModel(this ProtocolRecord protocolRecord) { if (protocolRecord == null) { return(null); } return(new ProtocolRecordViewModel() { customIntValue = protocolRecord.CustomIntValue, eventId = protocolRecord.eventId, extraTime = protocolRecord.ExtraTime, gameId = protocolRecord.gameId, id = protocolRecord.Id, minute = protocolRecord.Minute, personId = protocolRecord.personId, teamId = protocolRecord.teamId }); }
/// <summary> /// Creates package record based on protocol record. /// </summary> /// <param name="packageSession">The package session.</param> /// <param name="protocolRecord">The protocol record.</param> /// <param name="targetNode">The target node.</param> /// <returns>Package record</returns> public static PackageRecord CreateForProtocolRecord(PackageSession packageSession, ProtocolRecord protocolRecord, ReplicationNode targetNode) { var destinationSession = packageSession.Session; var result = new PackageRecord(destinationSession) { PackageSession = packageSession, UserName = protocolRecord.UserName, Description = protocolRecord.Description, ModifiedOn = protocolRecord.ModifiedOn, NewBlobValue = protocolRecord.NewBlobValue, PropertyName = protocolRecord.PropertyName, NewValue = protocolRecord.NewValue, OldValue = protocolRecord.OldValue, OperationType = protocolRecord.OperationType }; if (protocolRecord.AuditedObject != null && protocolRecord.AuditedObject.Target != null) { result.AuditedObject = PackageObjectReference.CreatePackageObjectReference(protocolRecord.AuditedObject.Target, destinationSession, targetNode); result.AuditedObject.ReplicationKey = protocolRecord.ReplicationKey; } if (protocolRecord.NewObject != null) { result.NewObject = PackageObjectReference.CreatePackageObjectReference(protocolRecord.NewObject.Target, destinationSession, targetNode); } if (protocolRecord.OldObject != null) { result.OldObject = PackageObjectReference.CreatePackageObjectReference(protocolRecord.OldObject.Target, destinationSession, targetNode); } return(result); }
public ProtocolRecordInfo(ProtocolRecord protocolRecord) { Guard.CheckNull(protocolRecord, nameof(protocolRecord)); ProtocolRecord = protocolRecord; if (ProtocolRecord.personId <= 0) { ProtocolRecord.personId = null; } if (ProtocolRecord.Minute < 0) { ProtocolRecord.Minute = null; } if (ProtocolRecord.CustomIntValue <= 0) { ProtocolRecord.CustomIntValue = null; } }
private void AddSubstatution(EntityLinkProtocolViewModel record, IEnumerable <ProtocolRecord> subs) { ProtocolRecord sub = subs.FirstOrDefault(s => s.CustomIntValue == int.Parse(record.main.id)); if (sub == null || !sub.CustomIntValue.HasValue) { return; } record.extra = new EntityLinkProtocolViewModel() { main = new EntityLinkViewModel() { id = sub.personId.ToString(), text = GetPersonName(sub.personId.Value), title = GetPersonName(sub.personId.Value) } }; protocolModelUtils.CalculateMinutes(sub, record.extra); AddSubstatution(record.extra, subs); }
private void FillRelations(IEnumerable <Game> games) { if (Guard.IsEmptyIEnumerable(games)) { return; } IEnumerable <Team> teams = new Team[0]; IEnumerable <Round> rounds = new Round[0]; IEnumerable <Stadium> stadiums = new Stadium[0]; IEnumerable <ProtocolRecord> protocols = new ProtocolRecord[0]; if (FillTourneys) { FillRounds = true; } if (FillTeams) { var teamDal = new TeamDal(); teamDal.SetContext(Context); var teamIds = new List <int>(); teamIds.AddRange(games.Select(g => g.homeId)); teamIds.AddRange(games.Select(g => g.awayId)); teams = teamDal.GetTeams(teamIds.Distinct()).ToList(); if (!teams.Any()) { throw new DalMappingException(nameof(teams), typeof(Game)); } } if (FillRounds) { var roundDal = new RoundDal(); roundDal.SetContext(Context); roundDal.FillTourneys = FillTourneys; var roundIds = new List <int>(); roundIds.AddRange(games.Select(g => (int)g.roundId)); rounds = roundDal.GetRounds(roundIds.Distinct()).ToList(); if (!rounds.Any()) { throw new DalMappingException(nameof(rounds), typeof(Game)); } } if (FillStadiums) { var stadiumDal = new StadiumDal(); stadiumDal.SetContext(Context); stadiumDal.FillCities = true; var stadiumIds = new List <int>(); stadiumIds.AddRange(games.Where(s => s.stadiumId.HasValue).Select(g => (int)g.stadiumId)); stadiums = stadiumDal.GetStadiums(stadiumIds.Distinct()).ToList(); } if (FillProtocols) { var protocolRecordDal = new ProtocolRecordDal(); var gameIds = new List <int>(); gameIds.AddRange(games.Select(g => g.Id).Distinct()); protocols = protocolRecordDal.GetProtocol(gameIds).ToList(); } foreach (Game game in games) { if (FillTeams && teams.Any()) { game.home = teams.FirstOrDefault(t => t.Id == game.homeId); if (game.home == null) { throw new DalMappingException(nameof(game.home), typeof(Game)); } game.away = teams.FirstOrDefault(t => t.Id == game.awayId); if (game.away == null) { throw new DalMappingException(nameof(game.away), typeof(Game)); } } else { game.home = null; game.away = null; } if (FillRounds && rounds.Any()) { game.round = rounds.FirstOrDefault(r => r.Id == game.roundId); if (game.round == null) { throw new DalMappingException(nameof(game.round), typeof(Game)); } } else { game.round = null; } if (FillStadiums && stadiums.Any()) { game.stadium = stadiums.FirstOrDefault(r => r.Id == game.stadiumId); } else { game.stadium = null; } if (FillProtocols && protocols.Any()) { game.ProtocolRecord = protocols.Where(p => p.gameId == game.Id).ToList(); } else { game.ProtocolRecord = null; } } }