Beispiel #1
0
        public void Delete(int id)
        {
            var entity = _context.Suppliers.Find(id);

            if (entity != null)
            {
                _context.Remove(entity);
            }
        }
Beispiel #2
0
        /// <summary>
        /// implementiert die Anforderung void setPreferredSupplierForProduct(Supplier s, Product c)
        /// aus technischen Gründen wurde ein weitere Parameter hinzugefügt (für sinnvolles Routing)
        /// </summary>
        /// <param name="s"> Der Supplier, dessen ID in preferredSupplier eingetragen werden soll </param>
        /// <param name="c"> Das Produkt, das aktualisert werden soll </param>
        /// <param name="productId"> Die ID des zu aktualisierenden Produkts </param>
        public void setPreferredSupplierForProduct(Supplier s, Product c, string productId)
        {
            var isSupplierThere = _supplierContext.Find <Supplier>(s.id);

            if (isSupplierThere == null)
            {
                throw new UnknownSupplierException(Constants.UnknownSupplierMessage);
            }
            var isProductThere = _supplierContext.Find <Product>(productId);

            if (isProductThere == null)
            {
                throw new UnknownProductException(Constants.UnknownProductMessage);
            }

            // TODO: update benutzen
            // Work-around
            // Update wirft Exception...
            _supplierContext.Remove <Product>(isProductThere);
            isProductThere = isProductThere.Clone(isSupplierThere.id);
            // _supplierContext.Update<Product>(isProductThere);
            _supplierContext.Add <Product>(isProductThere);
            _supplierContext.SaveChanges();
        }