Example #1
0
        public void Delete(int id)
        {
            Repository <Category> categoryRepository = new Repository <Category>(db);
            var category = db.Categories.Where(c => c.Id == id).FirstOrDefault();

            categoryRepository.Delete(category);
            db.SaveChanges();
        }
Example #2
0
        public void PostProduct(ProductJson productJson)
        {
            Repository <Product> productRepository = new Repository <Product>(db);
            var product = convertor.ConvertProductJsonToProduct(productJson);

            productRepository.Insert(product);
            db.SaveChanges();
        }
Example #3
0
        public void PostShoppingCart(ShoppingCartJson shoppingCartJson)
        {
            Repository <ShoppingCart> shoppingCartRepository = new Repository <ShoppingCart>(db);
            // préconversion pour récupérer l'ID
            var shoppingCart = convertor.ConvertToShoppingCart(shoppingCartJson);
            // insertion vers la db
            var entity = shoppingCartRepository.Insert2(shoppingCart);

            db.SaveChanges();
            //récupération de l'id
            //var entity = db.ShoppingCarts.Where(s => s == shoppingCart).FirstOrDefault();
            var entityID = entity.Id;

            //peupler les shoppings products
            entity.ShoppingProducts = convertor.ConvertShoppingProductJsonListToShoppingProductList(shoppingCartJson.shoppingProducts, entityID);
            db.SaveChanges();
        }