public static List <StatItem> GetCurrencyStatictic(int ms, string cs) { var list = new List <StatItem>(); using (var ctx = new ExchangeDataContext(cs)) { var orders = ctx.Orders.Where(x => x.DealDate > DateTime.Now.AddMilliseconds(-ms)).ToList(); if (orders.Any()) { var pr = orders.GroupBy(x => x.PriceId).ToList(); list.AddRange(from p in pr let key = p.Key where key != null let pp = ctx.Prices.First(x => x.Id == key) select new StatItem() { CurrencyType = (CurrencyTypeEnum)(Convert.ToInt32(pp.CurrencyCode)), Name = ((CurrencyTypeEnum)(Convert.ToInt32(pp.CurrencyCode))).ToString(), PriceId = (int)key, Price = pp.CurrencyPrice, DealCount = orders.Count(x => x.PriceId == key), MiddleValue = orders.Where(y => y.PriceId == key).Average(x => x.DealValue) }); } } return(list); }
public void DeleteDb(string connectionString) { using (var dc = new ExchangeDataContext(connectionString)) { dc.DeleteDatabase(); } }
public static void Update(ClientItem client, string cs) { using (var ctx = new ExchangeDataContext(cs)) { var c = ctx.Clients.Single(x => x.Id == client.Id); c.EndDateTime = client.EndDate; ctx.SubmitChanges(); } }
public static List <ClientItem> GetActiveList(string cs) { using (var ctx = new ExchangeDataContext(cs)) { return(ctx.Clients.Where(x => x.EndDateTime == null) .Select(y => new ClientItem() { Id = y.Id, StartDate = y.StartDateTime, EndDate = y.EndDateTime }).ToList()); } }
public static void Save(ClientItem client, string cs) { using (var ctx = new ExchangeDataContext(cs)) { var c = new Client { Id = client.Id, StartDateTime = client.StartDate, EndDateTime = client.EndDate }; ctx.Clients.InsertOnSubmit(c); ctx.SubmitChanges(); } }
public static void Save(List <PriceItem> prices, string cs) { using (var ctx = new ExchangeDataContext(cs)) { var list = prices.Select(priceItem => new Price { DateUpd = priceItem.DateUpdate, CurrencyCode = ((int)priceItem.CurrencyCode).ToString(CultureInfo.InvariantCulture), CurrencyPrice = priceItem.Price, }).ToList(); ctx.Prices.InsertAllOnSubmit(list); ctx.SubmitChanges(); } }
public static void Add(ServerLogItem item, string cs) { using (var ctx = new ExchangeDataContext(cs)) { var cl = new ServerLog() { EventTypeId = (int)item.EventType, EventDate = item.Date, Data = item.Data, ServerId = item.ServerId, AvailableClientsCount = item.AvailableClientsCount }; ctx.ServerLogs.InsertOnSubmit(cl); ctx.SubmitChanges(); } }
public static void Save(Common.OrderItem orderItem, string cs) { using (var ctx = new ExchangeDataContext(cs)) { var o = new Order { ClientId = orderItem.ClientId, PriceId = orderItem.PriceId, DealDate = orderItem.Date, DealValue = orderItem.Value }; ctx.Orders.InsertOnSubmit(o); ctx.SubmitChanges(); orderItem.Id = o.Id; } }
public static List <PriceItem> Get(string cs) { using (var ctx = new ExchangeDataContext(cs)) { return ((from h in ctx.Prices orderby h.DateUpd descending group h by h.CurrencyCode into g let f = g.FirstOrDefault() where f != null select new PriceItem { Id = f.Id, CurrencyCode = (CurrencyTypeEnum)Convert.ToInt32(f.CurrencyCode), Price = f.CurrencyPrice, DateUpdate = f.DateUpd }).ToList <PriceItem>()); } }
public static StatServerItem GetServerStatictic(int ms, string cs) { var item = new StatServerItem(); using (var ctx = new ExchangeDataContext(cs)) { var orders = ctx.Orders.Where(x => x.DealDate > DateTime.Now.AddMilliseconds(-ms)); if (orders.Any()) { item.DealCount = orders.Count(); item.DealValue = orders.Sum(y => y.DealValue); } var srv = ctx.ServerLogs.OrderByDescending(x => x.EventDate) .FirstOrDefault(x => x.EventTypeId == (int)EventTypeEnum.Running && x.EventDate > DateTime.Now.AddMilliseconds(-ms)); if (srv != null) { item.ServerName = srv.ServerId.ToString(); item.IsServerAvailable = true; var start = ctx.ServerLogs.FirstOrDefault(x => x.EventTypeId == (int)EventTypeEnum.Started && x.ServerId == srv.ServerId); if (start != null) { TimeSpan diff = DateTime.Now - start.EventDate; item.ServerWorkingHours = diff.Hours; item.ServerWorkingMinutes = diff.Minutes; item.ServerWorkingSeconds = diff.Seconds; } item.ClientCount = srv.AvailableClientsCount; } } return(item); }
public void CreateDb(string connectionString) { using (var dc = new ExchangeDataContext(connectionString)) { dc.CreateDatabase(); var currences = new[] { new Currency { Name = "RUB", Code = "643", FullName = "Russian Rouble" }, new Currency { Name = "USD", Code = "840", FullName = "US Dollar" }, new Currency { Name = "EUR", Code = "978", FullName = "Euro" }, new Currency { Name = "CHF", Code = "756", FullName = "Swiss franc" }, new Currency { Name = "JPY", Code = "392", FullName = "Japanese Yen" }, new Currency { Name = "GBP", Code = "826", FullName = "British Pound" }, new Currency { Name = "CAD", Code = "124", FullName = "Canadian Dollar" }, new Currency { Name = "CNY", Code = "156", FullName = "Chinese yen" }, new Currency { Name = "BRL", Code = "986", FullName = "Brazilian Real" } }; // заполнение справочника валют using (var scope = new TransactionScope()) { dc.Currencies.InsertAllOnSubmit(currences); dc.SubmitChanges(); scope.Complete(); } // заполнение справочника событий var eventTypes = new[] { new EventType { Id = 1, Name = "Server started" }, new EventType { Id = 2, Name = "Server stopped" }, new EventType { Id = 3, Name = "Server running" }, }; using (var scope = new TransactionScope()) { dc.EventTypes.InsertAllOnSubmit(eventTypes); dc.SubmitChanges(); scope.Complete(); } } }