//Delete public void Delete(int DrinkId) { var drink = new Drink { Id = DrinkId }; _coffeeDbContext.Entry(drink).State = EntityState.Deleted; _coffeeDbContext.SaveChanges(); }
public async Task GetCategoryByIdAsyncTestAsync() { var options = new DbContextOptionsBuilder <CoffeeDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (var context = new CoffeeDbContext(options)) { var doanCategory = new Category { Id = 1, CategoryName = "Đồ ăn", Drinks = new List <Drink>() }; var thucuongCategory = new Category { Id = 2, CategoryName = "Thức uống", Drinks = new List <Drink>() }; var coffeeCategory = new Category { Id = 3, CategoryName = "Coffee", Drinks = new List <Drink>() }; var trangmiengCategory = new Category { Id = 4, CategoryName = "Tráng miệng", Drinks = new List <Drink>() }; context.Categories.Add(doanCategory); context.Categories.Add(thucuongCategory); context.Categories.Add(coffeeCategory); context.Categories.Add(trangmiengCategory); context.SaveChanges(); } using (var context = new CoffeeDbContext(options)) { var service = new CategoryRepository(context); var result = await service.GetCategoryByIdAsync(4); //Assert.AreEqual(4, context.Categories.Count()); Assert.AreEqual(4, result.Id); } }
private void btnSave_Click(object sender, EventArgs e) { var product = new Product { Description = txtDecription.Text, Image = byteBlobData, ProductTypeId = (int)cboCategory.SelectedValue, Price = decimal.Parse(txtPrice.Text, CultureInfo.InvariantCulture) }; _db.Products.Add(product); _db.SaveChanges(); MessageBox.Show("Record saved"); }
public long Insert(USER entity) //Thêm mới user { db.USERs.Add(entity); db.SaveChanges(); return(entity.UserId); }
public int SaveChanges() { return(_context.SaveChanges()); }