public static void Initialize(MatchbookDbContext dbContext)
        {
            // Drop & re-create DB
            dbContext.Database.EnsureDeleted();
            dbContext.Database.EnsureCreated();

            // Data is already seeded?
            //if (dbContext.Orders.Any())
            //    return;

            // Do the initialization

            DataGenerator.KnownCurrencies
            .Select(code => new Currency {
                Code = code, Name = $"{code} currency"
            })
            .ForEach(currency => dbContext.Currencies.Add(currency));
            dbContext.SaveChanges();
            DataGenerator.KnownUnitsOfMeasure
            .Select(code => new UnitOfMeasure {
                Code = code, Name = $"{code} uom"
            })
            .ForEach(uom => dbContext.UnitsOfMeasure.Add(uom));
            dbContext.SaveChanges();

            DataGenerator.NewOrders()
            .Take(20)
            .ForEach(order => dbContext.Orders.Add(order));
            dbContext.SaveChanges();
        }
Beispiel #2
0
        public static ProductSpecification NewSavedProductSpec(MatchbookDbContext dbContext)
        {
            var spec = NewProductSpec();

            dbContext.ProductSpecifications.Add(spec);
            dbContext.SaveChanges();
            return(spec);
        }
Beispiel #3
0
        public static SubAccount NewSavedSubAccount(MatchbookDbContext dbContext)
        {
            var account = NewUnsavedSubAccount(dbContext);

            dbContext.SubAccounts.Add(account);
            dbContext.SaveChanges();
            return(account);
        }
        //public static string connectionString = "Server=localhost\\SQLEXPRESS;Database=Matchbook;Trusted_Connection=True;";

        public OrderLinkTestCase(DbContextFixture fixture)
        {
            this._fixture = fixture;

            //dbContextOptions = new DbContextOptionsBuilder<MatchbookDbContext>()
            //  .UseInMemoryDatabase(databaseName: "Matchbook").Options;

            MatchbookDbContextWithData = _fixture.NewDbContext();
        }
Beispiel #5
0
        public static SubAccount NewUnsavedSubAccount(MatchbookDbContext dbContext)
        {
            var clearingAccount         = NewClearingAccount();
            var internalClearingAccount = NewClearingAccount();

            dbContext.ClearingAccounts.AddRange(clearingAccount, internalClearingAccount);
            dbContext.SaveChanges();

            var account = NewSubAccount();

            account.ClearingAccountId         = clearingAccount.Id;
            account.InternalClearingAccountId = internalClearingAccount.Id;
            return(account);
        }
        public void Seed(MatchbookDbContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Orders.AddRange(
                DataGenerator.NewOrders()
                );

            //context.Post.AddRange(
            //    new Post() { Title = "Test Title 1", Description = "Test Description 1", CategoryId = 2, CreatedDate = DateTime.Now },
            //    new Post() { Title = "Test Title 2", Description = "Test Description 2", CategoryId = 3, CreatedDate = DateTime.Now }
            //);
            context.SaveChanges();
        }
Beispiel #7
0
        public (int, string) GetLinkCountByName(string name)
        {
            int    count   = 0;
            string message = string.Empty;

            try
            {
                MatchbookDbContext dbContext = new MatchbookDbContext();
                count = dbContext.OrderLink.Where(link => link.Name.ToLower() == name.ToLower()).Count();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(count, message);
        }
Beispiel #8
0
        public (int, string) CreateLink(string name)
        {
            int    linkId  = -1;
            string message = string.Empty;

            try
            {
                MatchbookDbContext dbContext = new MatchbookDbContext();
                OrderLink          orderLink = new OrderLink()
                {
                    Name = name
                };
                dbContext.OrderLink.Add(orderLink);
                dbContext.SaveChanges();
                linkId = dbContext.OrderLink.OrderByDescending(link => link.Id).FirstOrDefault().Id ?? -1;
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(linkId, message);
        }
Beispiel #9
0
        public (int, string) UpdateOrders(List <int> orderIds, int linkId)
        {
            int    success = 0;
            string message = string.Empty;

            try
            {
                MatchbookDbContext matchDbContext = new MatchbookDbContext();
                foreach (int orderId in orderIds)
                {
                    Order order = matchDbContext.Orders.Find(orderId);
                    order.LinkId = linkId;
                    matchDbContext.Orders.Update(order);
                }

                matchDbContext.SaveChanges();
                success = 1;
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(success, message);
        }
 public OrdersController(MatchbookDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Beispiel #11
0
        public List <Order> GetOrders(List <int> orderIds)
        {
            MatchbookDbContext dbContext = new MatchbookDbContext();

            return(dbContext.Orders.Where(order => orderIds.Contains(order.Id)).ToList());
        }