示例#1
0
 public IEnumerable <CommodityPrice> GetCommodityPrices()
 {
     using (var context = new InfoExchangeContext())
     {
         return(context.CommodityPrices.ToArray());
     }
 }
示例#2
0
 public IEnumerable <User> GetUsers()
 {
     using (var context = new InfoExchangeContext())
     {
         return(context.Users.ToArray());
     }
 }
示例#3
0
 public Commodity GetCommodity(Guid commodityID)
 {
     using (var context = new InfoExchangeContext())
     {
         return(context.Commodities.Find(commodityID));
     }
 }
示例#4
0
 public void UpadateAskLeg(AskLeg leg)
 {
     using (var context = new InfoExchangeContext())
     {
         UpadateAskLeg(leg);
     }
 }
示例#5
0
 private void UpdateAskLeg(AskLeg leg, InfoExchangeContext context)
 {
     leg.Ask = null;
     context.AskLegs.Attach(leg);
     context.Entry(leg).State = EntityState.Modified;
     context.SaveChanges();
 }
示例#6
0
 public void UpdateAsk(Ask ask)
 {
     using (var context = new InfoExchangeContext())
     {
         UpdateAsk(ask, context);
     }
 }
示例#7
0
 public void AddAsk(Ask ask)
 {
     using (var context = new InfoExchangeContext())
     {
         SubmitAsk(ask, context);
     }
 }
示例#8
0
 public IEnumerable <Ask> GetAsks()
 {
     using (var context = new InfoExchangeContext())
     {
         return(context.Asks.AsNoTracking().Include(a => a.CommodityBuy).Include(a => a.CommoditySell).Include(a => a.AskLegs).Where(
                    a => (a.ValidToDate == null || a.ValidToDate >= DateTime.UtcNow) && (a.BuyQuantity > 0 || a.SellQuantity > 0)).ToArray());
     }
 }
示例#9
0
 public IEnumerable <Ask> GetAsks(int commodityID)
 {
     using (var context = new InfoExchangeContext())
     {
         return(context.Asks.AsNoTracking().Include(a => a.CommodityBuy).Include(a => a.CommoditySell).Where(
                    a => a.CommodityBuyID == commodityID || a.CommoditySellID == commodityID).ToArray());
     }
 }
示例#10
0
 private void UpdateAsk(Ask ask, InfoExchangeContext context)
 {
     ask.CommodityBuy  = null;
     ask.CommoditySell = null;
     ask.User          = null;
     ask.AskLegs       = null;
     context.Asks.Attach(ask);
     context.Entry(ask).State = EntityState.Modified;
     context.SaveChanges();
 }
示例#11
0
        private void DeleteAsk(Ask ask, InfoExchangeContext context)
        {
            var dAsk = context.Asks.Find(ask.AskID);

            if (dAsk != null)
            {
                context.Asks.Remove(dAsk);
                context.SaveChanges();
            }
        }
示例#12
0
 private void SaveOrder(Order order, InfoExchangeContext context)
 {
     if (order.OrderID == Guid.Empty)
     {
         order.OrderID = Guid.NewGuid();
     }
     order.OrderDate = DateTime.UtcNow;
     foreach (var leg in order.OrderLegs)
     {
         leg.OrderID = order.OrderID;
         if (leg.OrderLegID == Guid.Empty)
         {
             leg.OrderLegID = Guid.NewGuid();
         }
         context.OrderLegs.Add(leg);
     }
     context.Orders.Add(order);
     context.SaveChanges();
 }
示例#13
0
        public void ExecuteAsk(Ask ask, IEnumerable <Order> orders, IEnumerable <Ask> orderLegAsks, IEnumerable <AskLeg> askLegs)
        {
            using (var context = new InfoExchangeContext())
            {
                using (var scope = new TransactionScope())
                {
                    AsksToUpdate.Enqueue(ask);
                    foreach (var order in orders)
                    {
                        SaveOrder(order, context);
                        if (orderLegAsks != null)
                        {
                            foreach (var orderAsk in orderLegAsks)
                            {
                                AsksToUpdate.Enqueue(orderAsk);
                            }
                        }
                    }

                    scope.Complete();
                }
            }
        }
示例#14
0
 private void SubmitAsk(Ask ask, InfoExchangeContext context)
 {
     ask.AskDate = DateTime.UtcNow;
     context.Asks.Add(ask);
     context.SaveChanges();
 }