public async Task <IActionResult> PutProducts(int id, Products products) { if (id != products.Id) { return(BadRequest()); } _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IEnumerable <Flavor> > PutFbDetails([FromRoute] int id, [FromBody] Flavor flavor) { _context.Entry(flavor).State = EntityState.Modified; await _context.SaveChangesAsync(); return(_context.Flavors.Where(r => r.FBDetailsId == flavor.FBDetailsId)); }
public async Task <IEnumerable <FBDetails> > PutfbDetail([FromRoute] int id, [FromBody] FBDetails fbdetail) { _context.Entry(fbdetail).State = EntityState.Modified; await _context.SaveChangesAsync(); return(_context.FBDetails.Where(r => r.MenuItemId == fbdetail.MenuItemId)); }
public async Task <IActionResult> Create([Bind("ProductID,Description,Quantity,Price")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("UserID,FirstName,LastName,Email,Password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); _session.SetString("User", user.FirstName); _session.SetInt32("ID", user.UserID); // return RedirectToAction("Index", "Home"); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public static async Task SeedAsync(CoffeeShopContext ctx) { if (!ctx.Categories.Any()) { var categoriesData = File.ReadAllText("../CofeeShopDAL/SeedData/Assets/categories.json"); var categories = JsonSerializer.Deserialize <List <Category> >(categoriesData); foreach (var item in categories) { ctx.Categories.Add(item); } await ctx.SaveChangesAsync(); } if (!ctx.ProductTypes.Any()) { var typesData = File.ReadAllText("../CofeeShopDAL/SeedData/Assets/types.json"); var types = JsonSerializer.Deserialize <List <ProductType> >(typesData); foreach (var item in types) { ctx.ProductTypes.Add(item); } await ctx.SaveChangesAsync(); } if (!ctx.Products.Any()) { var productsData = File.ReadAllText("../CofeeShopDAL/SeedData/Assets/products.json"); var products = JsonSerializer.Deserialize <List <Product> >(productsData); foreach (var item in products) { ctx.Products.Add(item); } await ctx.SaveChangesAsync(); } }
public async Task <int> SaveChanges() { return(await Db.SaveChangesAsync()); }
public async Task AddCoffeeShop(CoffeeShop coffeeShop) { _context.CoffeeShops.Add(coffeeShop); await _context.SaveChangesAsync(); }
public async Task Create(T entity) { await _context.Set <T>().AddAsync(entity); await _context.SaveChangesAsync(); }