コード例 #1
0
        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());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: DbInitializer.cs プロジェクト: DariiaBormot/Store
        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();
            }
        }
コード例 #7
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }
コード例 #8
0
        public async Task AddCoffeeShop(CoffeeShop coffeeShop)
        {
            _context.CoffeeShops.Add(coffeeShop);

            await _context.SaveChangesAsync();
        }
コード例 #9
0
        public async Task Create(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }