public void AddToFavourites(string userId, Drink drink) { if (IsFavourite(userId, drink.DrinkId)) { return; } _context.UserDrinks.Add(new UserDrink { DrinkId = drink.DrinkId, Drink = drink, AppUserId = userId, AppUser = _context.Users.Find(userId) }); _context.SaveChanges(); }
public TestWithSqlite() { _connection = new SqliteConnection(InMemoryConnectionString); _connection.Open(); var options = new DbContextOptionsBuilder <DrinkAppContext>() .UseSqlite(_connection) .Options; Context = new DrinkAppContext(options); Context.Database.EnsureCreated(); var data = new DrinkLoader().InitializeDrinksFromFile(); // Add drinks to the database Context.AddRange(data); Context.SaveChanges(); Repository = new DrinkRepository(Context); }
public void SetSetting(Settings settings, string value) { _context.Settings.Find((int)settings).Value = value; _context.SaveChanges(); }