public void ConstructorAcceptsPlayer() { var player = new Player(); var context = new TradeContext(player); Assert.Equal(player, context.Contractor); }
public void BegintradeWithNullPlayerThrownTradeException() { var player = new Player(); var context = new TradeContext(player); var exception = Xunit.Assert.Throws <TradeException>(() => context.BeginTrade(null)); Assert.Equal(TradeStatus.PlayerNotFound, exception.Code); }
public TradeController(TradeContext context) { _context = context; if (_context.TodoItems.Count() == 0) { _context.TodoItems.Add(new Trade { Product = "Item1" }); _context.SaveChanges(); } }
public ActionResult Authorize(Client model) { using (TradeContext db = new TradeContext()) { var clientDetails = db.Clients.Where(x => x.Username == model.Username && x.Password == model.Password).FirstOrDefault(); if (clientDetails == null) { return(View("Index", model)); } else { Session["Username"] = clientDetails.Username; Session["clientID"] = clientDetails.ClientID; return(RedirectToAction("Index", "Home")); } } }
public IActionResult Get(string identifier) { // This has implemented fairly basic caching of data for a minute. // In a production environment you may want to look at sql dependency injection to flush the cache only // if the underlying database values have changed. OMSTradeData cacheEntry = null; if (identifier != null && !_cache.TryGetValue(identifier.ToUpper(), out cacheEntry)) { var data = new TradeContext(); cacheEntry = data.TradeData.FirstOrDefault(t => t.Identifier == identifier); MemoryCacheEntryOptions options = new MemoryCacheEntryOptions(); options.AbsoluteExpiration = DateTime.Now.AddMinutes(1); options.SlidingExpiration = TimeSpan.FromMinutes(1); _cache.Set(cacheEntry.Identifier, cacheEntry, options); } return(Json(cacheEntry)); }
public void BigFatDoEverything() { var optionsBuilder = new DbContextOptionsBuilder <TradeContext>(); optionsBuilder.UseSqlServer("Server=.;Database=Redburn_Lofty1;Trusted_Connection = True;"); var liveContext = new TradeContext(optionsBuilder.Options); //liveContext.Database.Migrate(); liveContext.Database.EnsureCreated(); // shouldnt be necessary but for some reason db is not getting generated on savechanges. Investigate when given time. var tradeService = new TradeDataService(liveContext); var tradeStream = _tradeDataStream.GetTradeStream(); var tradeMessage = new OMSTradeDataMessage(tradeStream); var result = tradeService.CommitTrades(tradeMessage); Assert.True(result); }
public CounterpartyController(TradeContext _context) { context = _context; }
public ActionResult Stats() { string userId = User.Identity.GetUserId(); TradeContext db = new TradeContext(); StatisticsDTO stats = new StatisticsDTO(); var currentUserCategories = (from cat in db.Categories where cat.UserId == userId select new CategoryDTO { Id = cat.Id, Name = cat.Name, Products = cat.Products.Select(prod => new ProductDTO() { Id = prod.Id, Name = prod.Name, Price = prod.Price, }).ToList() }).ToList(); System.Diagnostics.Debug.WriteLine("\n\nList of products:"); foreach (var x in currentUserCategories) { System.Diagnostics.Debug.WriteLine(x.Products.Count()); } System.Diagnostics.Debug.WriteLine("\n\nList of clients with the amount of products they demand:"); var client = (from c in db.Clients where c.UserId == userId orderby c.Name select new ClientDTO { Id = c.Id, Name = c.Name, Phone = c.Phone, Email = c.Email, Products = c.Products.Select(prod => new ProductDTO() { Id = prod.Id, Name = prod.Name, Price = prod.Price, }).ToList() }).ToList(); foreach (var x in client) { System.Diagnostics.Debug.WriteLine(x.Products.Count()); } System.Diagnostics.Debug.WriteLine("\n\nList of status's:"); var status = (from s in db.Status where s.UserId == userId select new StatusDTO { Id = s.Id, Name = s.Name, Products = s.Products.Select(prod => new ProductDTO() { Id = prod.Id, Name = prod.Name, Price = prod.Price }).ToList() }).ToList(); foreach (var x in status) { System.Diagnostics.Debug.WriteLine(x.Products.Count()); } stats.Categories = currentUserCategories; stats.Clients = client; stats.Status = status; ViewBag.Message = "Stats page."; return(View(stats)); }
public TradesController(TradeContext context) { _context = context; }
public OMSTradeDataHandler() { _context = new TradeContext(); }
public CustomerService(ILifetimeScope container, IConfiguration configuration, ICacheService cacheService, TradeContext tradeContext) { cacheService.InitCacheService(configuration.GetSection("modules:2:properties:RedisConnection").Value); //启动缓存客户端 tradeContext.Database.EnsureCreated(); //自动迁移数据库 }
public TradeUnitOfWork(string connectionString) { this._db = new TradeContext(connectionString); this.Shops = new ShopRepository(this._db); this.Products = new ProductRepository(this._db); }
public ProductRepository(TradeContext dbContext) { this._db = dbContext; }
public TradeMessageHandler() { _context = new TradeContext(); }
public TradeController(TradeContext _context) { context = _context; }
public ActionResult Index(HttpPostedFileBase postedFile) { if (postedFile != null) { try { string fileExtension = Path.GetExtension(postedFile.FileName); //Validate uploaded file and return error. if (fileExtension != ".xls" && fileExtension != ".xlsx") { ViewBag.Message = "Please select the excel file with .xls or .xlsx extension"; return(View()); } string folderPath = Server.MapPath("~/UploadedFiles/"); //Check Directory exists else create one if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } //Save file to folder var filePath = folderPath + Path.GetFileName(postedFile.FileName); postedFile.SaveAs(filePath); //Get file extension string excelConString = ""; //Get connection string using extension switch (fileExtension) { //If uploaded file is Excel 1997-2007. case ".xls": excelConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"; break; //If uploaded file is Excel 2007 and above case ".xlsx": excelConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"; break; } //Read data from first sheet of excel into datatable DataTable dt = new DataTable(); excelConString = string.Format(excelConString, filePath); using (OleDbConnection excelOledbConnection = new OleDbConnection(excelConString)) { using (OleDbCommand excelDbCommand = new OleDbCommand()) { using (OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter()) { excelDbCommand.Connection = excelOledbConnection; excelOledbConnection.Open(); //Get schema from excel sheet DataTable excelSchema = GetSchemaFromExcel(excelOledbConnection); //Get sheet name string sheetName = excelSchema.Rows[0]["TABLE_NAME"].ToString(); excelOledbConnection.Close(); //Read Data from First Sheet. excelOledbConnection.Open(); excelDbCommand.CommandText = "SELECT * From [" + sheetName + "]"; excelDataAdapter.SelectCommand = excelDbCommand; //Fill datatable from adapter excelDataAdapter.Fill(dt); excelOledbConnection.Close(); } } } //Insert records to Trade table. using (var context = new TradeContext()) { //Loop through datatable and add trade data to trade table. foreach (System.Data.DataRow row in dt.Rows) { context.Trades.Add(GetTradeFromExcelRow(row)); } context.SaveChanges(); } ViewBag.Message = "Data Imported Successfully."; } catch (Exception ex) { ViewBag.Message = ex.Message; } } else { ViewBag.Message = "Please select the file first to upload."; } return(View()); }
public ShopRepository(TradeContext dbContext) { this._db = dbContext; }
public static void MigrateDB() { var context = new TradeContext(); context.Database.EnsureCreated(); // Doesn't seem autocreated in netcore? }