示例#1
0
        public async Task <IActionResult> Create([Bind("SupplierId,SupplierName,SupplierAbbr,SupplierClassify,SupplierCompetentProducts,SupplierBuyer,SupplierProvince,SupplierCity,SupplierAddress,SupplierEnable")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
示例#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();
        }
示例#3
0
        public ActionResult CreateSupplier([FromBody] Supplier supplier)
        {
            try
            {
                if (supplier == null)
                {
                    return(BadRequest("Supplier object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                _context.Add(supplier);
                _context.SaveChanges();

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex}"));
            }
        }