private static Company.IBusinessUnit GetBusinessUnit(FormalizeDocumentsParser.IExchangeParticipant participant) { var units = Company.BusinessUnits.GetAll() .Where(b => b.TIN == participant.Tin) .ToList(); if (units.Count > 1) { units = units.Where(b => b.TRRC == participant.Trrc).ToList(); } if (units.Count > 1) { units = units.Where(b => b.Status == CoreEntities.DatabookEntry.Status.Active).ToList(); } if (units.Any()) { return(units.Single()); } return(null); }
private static ExchangeCore.IBusinessUnitBox GetBox(FormalizeDocumentsParser.IExchangeParticipant participant) { var boxes = ExchangeCore.BusinessUnitBoxes.GetAll() .Where(b => b.BusinessUnit.TIN == participant.Tin) .ToList(); if (boxes.Count > 1) { boxes = boxes.Where(b => b.BusinessUnit.TRRC == participant.Trrc).ToList(); } if (boxes.Count > 1) { boxes = boxes.Where(b => b.Status == CoreEntities.DatabookEntry.Status.Active).ToList(); } if (boxes.Any()) { return(boxes.Single()); } return(null); }
private static Parties.ICounterparty GetCounterparty(FormalizeDocumentsParser.IExchangeParticipant participant, ExchangeCore.IBusinessUnitBox box, bool canExchange) { var counterparties = Parties.Counterparties.GetAll() .Where(b => b.TIN == participant.Tin) .ToList(); if (canExchange) { counterparties = counterparties.Where(c => c.ExchangeBoxes.Any(b => b.Box == box)).ToList(); } if (counterparties.Count > 1) { counterparties = counterparties.Where(b => b.Status == CoreEntities.DatabookEntry.Status.Active).ToList(); } if (counterparties.Count > 1) { if (!string.IsNullOrWhiteSpace(participant.Trrc)) { counterparties = counterparties.OfType <Parties.ICompanyBase>().Where(b => b.TRRC == participant.Trrc).ToList <Parties.ICounterparty>(); } else { counterparties = counterparties.Where(b => !Parties.CompanyBases.Is(b)).ToList(); } } if (counterparties.Count > 1 && counterparties.Any(b => b.CanExchange == true)) { counterparties = counterparties.Where(b => b.CanExchange == true).ToList(); } if (counterparties.Any()) { return(counterparties.Single()); } return(null); }