示例#1
0
 public Domain.Stock FindBySymbol(string stockSymbol)
 {
     using (FhQuotesContext ctx = new FhQuotesContext())
     {
         return(ctx.Stocks.Find(stockSymbol).ToDomain());
     }
 }
示例#2
0
 public ICollection <string> FindAllSymbols()
 {
     using (FhQuotesContext ctx = new FhQuotesContext())
     {
         return(ctx.Stocks.Select(stock => stock.Symbol).ToList());
     }
 }
示例#3
0
 public ICollection <Domain.Stock> FindAll()
 {
     using (FhQuotesContext ctx = new FhQuotesContext())
     {
         // First materialize then convert to doamin model !!!!
         return(ctx.Stocks.AsEnumerable().Select(stock => stock.ToDomain()).ToList());
     }
 }
示例#4
0
 public Domain.Quote FindLastQuote(string stockSymbol)
 {
     using (FhQuotesContext ctx = new FhQuotesContext())
     {
         return(ctx.Quotes.Where(quote => quote.Stock.Symbol.Equals(stockSymbol))
                .OrderByDescending(q => q.Time)
                .FirstOrDefault().ToDomain());
     }
 }
示例#5
0
 public ICollection <Domain.Quote> FindQuotesInRange(string stockSymbol, DateTime from, DateTime to)
 {
     using (FhQuotesContext ctx = new FhQuotesContext())
     {
         return(ctx.Quotes.Where(q => q.Stock.Symbol.Equals(stockSymbol))
                .Where(q => q.Time.CompareTo(from) >= 0)
                .Where(q => q.Time.CompareTo(to) <= 0)
                .OrderByDescending(q => q.Time)
                .AsEnumerable().Select(q => q.ToDomain())
                .ToList());
     }
 }
示例#6
0
        public bool Insert(Domain.Stock stock)
        {
            using (FhQuotesContext ctx = new FhQuotesContext())
            {
                if (ctx.Stocks.Find(stock.Symbol) == null)
                {
                    ctx.Stocks.Add(stock.ToEF());
                    ctx.SaveChanges();
                    return(true);
                }

                return(false);
            }
        }
示例#7
0
        public bool Insert(string stockSymbol, Domain.Quote quote)
        {
            using (FhQuotesContext ctx = new FhQuotesContext())
            {
                Stock stock = ctx.Stocks.Find(stockSymbol);
                if (stock == null)
                {
                    return(false);
                }

                var quoteEF = quote.ToEF();
                quoteEF.Stock = stock;
                ctx.Quotes.Add(quoteEF);
                ctx.SaveChanges();

                return(true);
            }
        }
示例#8
0
 public DbInitializer(FhQuotesContext context)
 {
     this.Context = context;
 }
 public QuoteDao(FhQuotesContext context)
 {
     this.context = context;
 }
 public StockDao(FhQuotesContext context)
 {
     this.context = context;
 }