Example #1
0
        /// <summary>
        /// implementiert die Anforderung Supplier findPreferredSupplier(Product p)
        /// </summary>
        /// <param name="p"> Das Produkt, welches als Suchkriterium benutzt wird </param>
        /// <returns> Den Supplier, der von jenem Produkt bevorzugt wird </returns>
        public Supplier findPreferredSupplier(Product p)
        {
            var isProductThere = _supplierContext.FindAsync <Product>(p.id);

            if (isProductThere == null)
            {
                throw new UnknownProductException(Constants.UnknownProductMessage);
            }
            // Erinnerung: "preferredSupplier" ist Fremdschlüssel und bezieht sich auf "id" der Tabelle "Supplier"
            var result = _supplierContext.Supplier.Find(p.preferredSupplier);

            if (result == null)
            {
                throw new UnknownSupplierException(Constants.UnknownSupplierMessage);
            }
            return(result);
        }