public Key(String tickerA, String tickerB, CorrelationPeriodType periodType) { if (String.IsNullOrWhiteSpace(tickerA)) { throw new ArgumentException("tickerA"); } if (String.IsNullOrWhiteSpace(tickerB)) { throw new ArgumentException("tickerB"); } if (tickerA.Equals(tickerB, StringComparison.CurrentCultureIgnoreCase)) { throw new ArgumentException("tickers are equal"); } toString = "[" + periodType.ToString() + "] [" + tickerA + "] [" + tickerB + "]"; hashCode = ("[" + periodType.ToString() + "]").GetHashCode() ^ ("[" + tickerA + "]").GetHashCode() ^ ("[" + tickerB + "]").GetHashCode(); this.tickerB = tickerB; this.tickerA = tickerA; this.periodType = periodType; }
public ElementCorrelation UpdateElementCorrelation(String tickerA, String tickerB, CorrelationPeriodType correlationPeriodType, Decimal value) { Byte correlationPeriodTypeValue = (Byte)correlationPeriodType; using (FinanceDBEntities context = new FinanceDBEntities()) { using (TransactionScope transaction = new TransactionScope()) { ElementCorrelation item = FirstElementOrNull <ElementCorrelation>((from er in context.ElementCorrelation where er.PeriodType == correlationPeriodTypeValue && (er.TickerA == tickerA && er.TickerB == tickerB || er.TickerA == tickerB && er.TickerB == tickerA) select er).ToArray <ElementCorrelation>()); if (null != item) { item.Upd = DateTime.Now; item.Correlation = value; LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Updating existing item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString()); } else { item = context.ElementCorrelation.CreateObject(); item.TickerB = tickerB; item.TickerA = tickerA; item.PeriodType = correlationPeriodTypeValue; item.Upd = DateTime.Now; item.Correlation = value; LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Adding new item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString()); context.ElementCorrelation.AddObject(item); } context.SaveChanges(); transaction.Complete(); return(item); } } }