Beispiel #1
0
        public Model.Basket Add(Model.Basket basket)
        {
            _dbContext.Baskets.Add(basket);
            _dbContext.SaveChanges();

            return(basket);
        }
 private int SaveChanges()
 {
     try
     {
         return(_context.SaveChanges());
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
Beispiel #3
0
        public DatabaseFixture()
        {
            DbContextOptions <BasketDbContext> dbOptions = new DbContextOptionsBuilder <BasketDbContext>()
                                                           .UseInMemoryDatabase(databaseName: "TestBasket")
                                                           .Options;

            basketDbContext  = new BasketDbContext(dbOptions);
            basketRepository = new BasketRepository(basketDbContext);

            //setup some data
            Basket existingBasket = new Basket()
            {
                Id = TestBasketId
            };

            existingBasket.AddItem(TestItemId, 10, 2);

            basketDbContext.Baskets.Add(existingBasket);
            basketDbContext.SaveChanges();
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using var context = new BasketDbContext(
                      serviceProvider.GetRequiredService <DbContextOptions <BasketDbContext> >());
            context.Customers.AddRange(
                new Customer
            {
                CustomerId = 1,
                FirstName  = "Tuğrul",
                LastName   = "Şimşirli"
            },
                new Customer
            {
                CustomerId = 2,
                FirstName  = "Mahatma",
                LastName   = "Gandhi"
            });

            context.Products.AddRange(
                new Product
            {
                Id           = 1,
                ProductName  = "C#",
                ProductStock = 100
            },
                new Product
            {
                Id           = 2,
                ProductName  = "Python",
                ProductStock = 0
            },
                new Product
            {
                Id           = 3,
                ProductName  = "Javascript",
                ProductStock = 50
            });

            context.SaveChanges();
        }
Beispiel #5
0
 public int SaveChanges()
 {
     return(context.SaveChanges());
 }