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());
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }
Esempio n. 8
0
        public async Task AddCoffeeShop(CoffeeShop coffeeShop)
        {
            _context.CoffeeShops.Add(coffeeShop);

            await _context.SaveChangesAsync();
        }
Esempio n. 9
0
        public async Task Create(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }