Пример #1
0
        public IEnumerable PutProduct(int id, Product product)
        {
            product.Id = id;

            if (Repository.Update(product))
            {
                return Repository.GetAll();
            }
            return null;
        }
Пример #2
0
        public Product Add(Product item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            // TO DO : Code to save record into database
            item.Id = _nextId++;
            _products.Add(item);

            return item;
        }
Пример #3
0
        public bool Update(Product item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            // TO DO : Code to update record into database
            var index = _products.FindIndex(p => p.Id == item.Id);
            if (index == -1)
            {
                return false;
            }
            _products.RemoveAt(index);
            _products.Insert(index, item);

            return true;
        }
Пример #4
0
 public Product PostProduct(Product item)
 {
     return Repository.Add(item);
 }