public void Test1() { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <DrinkContext>() .UseSqlite(connection) .Options; using (var context = new DrinkContext(options)) { context.Database.EnsureCreated(); } using (var context = new DrinkContext(options)) { } } finally { connection.Close(); } }
/// <summary> /// Method for creating a drink and saving it to the db /// </summary> /// <param name="drink"></param> public void CreateDrink(Drink drink) { using (var context = new DrinkContext()) { context.Drinks.Add(drink); context.SaveChanges(); } }
/// <summary> /// Method to remove a drink object that has been retrieved from the db /// and deleting it /// </summary> /// <param name="drink"></param> public void RemoveDrink(Drink drink) { using (var context = new DrinkContext()) { context.Entry(drink).State = EntityState.Deleted; context.Drinks.Remove(drink); context.SaveChanges(); } }
/// <summary> /// Method to retrieve all the unique drinks in the db /// </summary> /// <returns></returns> public List <Drink> GetUniqueDrinks() { List <Drink> drinks; using (var context = new DrinkContext()) { drinks = context.Drinks.Distinct().ToList(); } return(drinks); }
protected override void Seed(DrinkContext context) { context.Database.ExecuteSqlCommand("delete from Drinks"); context.Database.ExecuteSqlCommand("delete from Coins"); context.Drinks.AddOrUpdate( new Drink { Id = 1, Caption = "—ок апельсиновый", Cost = 20, IsDeleted = false, Count = 2, Image = @"orange.jpg" }, new Drink { Id = 1, Caption = "—ок ¤блочный", Cost = 18, IsDeleted = false, Count = 2, Image = @"apple.jpg" }, new Drink { Id = 1, Caption = "—ок мультифрутовый", Cost = 15, IsDeleted = false, Count = 2, Image = @"multy.jpg" }, new Drink { Id = 1, Caption = "—ок томатный", Cost = 10, IsDeleted = false, Count = 0, Image = @"tomato.jpg" }, new Drink { Id = 1, Caption = "—ок абрикосовый", Cost = 13, IsDeleted = false, Count = 3, Image = @"apricote.jpg" } ); context.SaveChanges(); context.Coins.AddOrUpdate( new Coin { Id = 1, Caption = "1 рубль", Count = 0, IsAllowed = true, IsDeleted = false, Value = 1, Image = "1rub.jpg" }, new Coin { Id = 2, Caption = "2 рубл¤", Count = 0, IsAllowed = true, IsDeleted = false, Value = 2, Image = "2rub.jpg" }, new Coin { Id = 5, Caption = "5 рублей", Count = 0, IsAllowed = true, IsDeleted = false, Value = 5, Image = "5rub.jpg" }, new Coin { Id = 10, Caption = "10 рублей", Count = 0, IsAllowed = true, IsDeleted = false, Value = 10, Image = "10rub.jpg" } ); context.SaveChanges(); context.Users.AddOrUpdate( new User { Id = 1, IsDeleted = false, Name = "Admin", SecretKey = "secret12345" } ); context.SaveChanges(); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
public DrinkController(DrinkContext context) { _context = context; if (_context.Drinks.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. _context.SaveChanges(); } }
/// <summary> /// Method to search for a drink in the db by a name /// </summary> /// <param name="name"></param> /// <returns></returns> public List <Drink> SearchDrink(string name) { List <Drink> drinks; using (var context = new DrinkContext()) { drinks = context.Drinks .Include((drink) => drink.Products.Select((product) => product.Product)) .Where((drink) => drink.Name == name).ToList(); } return(drinks); }
public void TestMethod1() { DrinkContext db = new DrinkContext(); CoffeeStore charleys = new CoffeeStore() { Eircode = "T12GH46", City = City.Dublin, OpeningTime = OpeningHour.AM0700, ClosingTime = ClosingHour.PM1800, Location = "dublin fair city", StoreName = "charleys", hasWifi = true }; List <Review> reviews = new List <Review>(); reviews.Add(new Review() { CustomerName = "Stevo", CustomerEmail = "*****@*****.**", Eircode = charleys.Eircode, Comment = "It was great", Rating = 4 }); reviews.Add(new Review() { CustomerName = "john", CustomerEmail = "*****@*****.**", Eircode = charleys.Eircode, Comment = "It was great", Rating = 3 }); reviews.Add(new Review() { CustomerName = "pete", CustomerEmail = "*****@*****.**", Eircode = charleys.Eircode, Comment = "It wasn't great", Rating = 2 }); Assert.AreEqual(charleys.StoreRating, 3); }
public HomeController(DrinkContext DrinkDatabase) { drinkContext = DrinkDatabase; }
public Repository(DrinkContext context) { _context = context; }
public UnitOfWork(DrinkContext context) { _context = context; }
public DrinksController(DrinkContext context) { _context = context; }
public DrinkService(DrinkContext drinkContext) { _drinkContext = drinkContext; _drinkContext.Database.EnsureCreated(); }
public Database() { context = new DrinkContext(); sender = new Sender(); }
static void Main(string[] args) { var options = new DbContextOptionsBuilder <DrinkContext>().Options; var _drinkContext = new DrinkContext(options); _drinkContext.Database.EnsureCreated(); var _ingredients = new List <IngredientModel>() { new IngredientModel() { Type = "Vodka", AddiType = AddiType.PushDosed, Unit = Unit.CL }, //1 new IngredientModel() { Type = "Gin", AddiType = AddiType.PushDosed, Unit = Unit.CL }, // 2 new IngredientModel() { Type = "Rum", AddiType = AddiType.PushDosed, Unit = Unit.CL }, // 3 new IngredientModel() { Type = "Tequila", AddiType = AddiType.PushDosed, Unit = Unit.CL }, // 4 new IngredientModel() { Type = "Cola", AddiType = AddiType.Poured, Unit = Unit.CL }, // 5 new IngredientModel() { Type = "Club soda", AddiType = AddiType.Poured, Unit = Unit.CL }, //6 new IngredientModel() { Type = "Apple juice", AddiType = AddiType.Poured, Unit = Unit.CL }, // 7 new IngredientModel() { Type = "Orange juice", AddiType = AddiType.Poured, Unit = Unit.CL }, // 8 new IngredientModel() { Type = "Salt", AddiType = AddiType.Extra, Unit = Unit.Pinches }, // 9 new IngredientModel() { Type = "Lemon Slice", AddiType = AddiType.Extra, Unit = Unit.Pcs } // 10 }; _drinkContext.AddRange(_ingredients); _drinkContext.SaveChanges(); var _drinks = new List <DrinkModel>(); _drinks.Add( new DrinkModel() { Name = "screwDriver", description = "dsaf", Addis = new List <AddiModel>() { new AddiModel() { Ingredient = _ingredients[0], Amount = 2 }, new AddiModel() { Ingredient = _ingredients[7], Amount = 14 } } } ); _drinks.Add( new DrinkModel() { Name = "Rum n coke", description = "dsaf", Addis = new List <AddiModel>() { new AddiModel() { Ingredient = _ingredients[2], Amount = 2 }, new AddiModel() { Ingredient = _ingredients[4], Amount = 14 } } } ); _drinks.Add( new DrinkModel() { Name = "Død", description = "dsaf", Addis = new List <AddiModel>() { new AddiModel() { Ingredient = _ingredients[3], Amount = 2 }, new AddiModel() { Ingredient = _ingredients[8], Amount = 1 }, new AddiModel() { Ingredient = _ingredients[9], Amount = 1 }, } } ); _drinkContext.AddRange(_drinks); _drinkContext.SaveChanges(); var test = _drinkContext.Drinks.Include(x => x.Addis).ThenInclude(Addi => Addi.Ingredient).Where(i => i.Id == 1).FirstOrDefault(); var test2 = Drink.Create(test); }
public UserRepository(DrinkContext context) : base(context) { }
public UnitOfWork() { _context = new DrinkContext(); }