public ElementCorrelationResult(ElementCorrelation internalItem) { if (null == internalItem) { throw new ArgumentNullException("internalItem"); } this.internalItem = internalItem; this.itemKey = new Key(internalItem.TickerA, internalItem.TickerB, (CorrelationPeriodType)internalItem.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); } } }