Ejemplo n.º 1
0
        public void UpdateProductStore(Productstore productstore)
        {
            var prodst = (from ps in _context.Productstore
                          where ps.Id_product == productstore.Id_product && ps.Id_store == productstore.Id_store
                          select ps).SingleOrDefault();

            prodst.Availability = productstore.Availability;
            prodst.Price        = productstore.Price;
            _context.SaveChanges();
        }
        public IActionResult UpdateProduct([FromBody] ProductStoreModel model)
        {
            Productstore productStore = new Productstore();

            productStore.Id_product = model.Id_product; productStore.Id_store = model.Id_store;
            productStore.Price      = model.Price; productStore.Availability = model.Availability;
            try
            {
                _storeService.UpdateProductStore(productStore);
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
            return(Ok());
        }
        public IActionResult FilterProductsByStoreId(int store_id)
        {
            var products = _productService.GetProductsByStoreId(store_id);
            List <ProductPriceAvailModel> result = new List <ProductPriceAvailModel>();
            var iter = products.GetEnumerator();

            iter.Reset();
            iter.MoveNext();
            while (iter.Current != null)
            {
                Products prod = iter.Current;
                ProductPriceAvailModel temp = new ProductPriceAvailModel();
                temp.Id     = prod.Id; temp.Name = prod.Name; temp.Description = prod.Description; temp.Producer = prod.Producer;
                temp.Weight = prod.Weight; temp.Category = prod.Category;
                Productstore ps = _productService.GetProductPriceAvail(prod.Id, store_id);
                temp.Price = ps.Price; temp.Availability = ps.Availability;
                result.Add(temp);
                iter.MoveNext();
            }
            return(Ok(result));
        }
        public IActionResult CreateProduct([FromBody] CreateProductModel model)
        {
            Products product = new Products();

            product.Name     = model.Name; product.Producer = model.Producer; product.Weight = model.Weight;
            product.Category = model.Category; product.Description = model.Description; product.Bulk_Product = model.Bulk_product;
            try
            {
                var          createdProduct = _productService.CreateProduct(product);
                Productstore productstore   = new Productstore();
                productstore.Id_product   = createdProduct.Id;
                productstore.Id_store     = model.Id_store;
                productstore.Price        = model.Price;
                productstore.Availability = model.Availability;
                _storeService.CreateProductStore(productstore);
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
            return(Ok());
        }
Ejemplo n.º 5
0
 public void CreateProductStore(Productstore productstore)
 {
     _context.Add(productstore);
     _context.SaveChanges();
 }