Пример #1
0
        /// <summary>
        /// This takes in productmodell / product giving it and guid id and add it to the database.
        /// </summary>
        /// <param name="ínputProduct"></param>
        /// <returns></returns>
        public async Task createProductAsync(ProductModell ínputProduct)
        {
            try
            {
                if (ínputProduct != null)
                {
                    ínputProduct.productID = Guid.NewGuid();

                    while (await validateIDToDatabaseAsync(ínputProduct) == true)
                    {
                        ínputProduct.productID = Guid.NewGuid();
                    }

                    ProductsContext.Products.Add(ínputProduct);
                    await ProductsContext.SaveChangesAsync();
                }
                else
                {
                    throw new InvalidOperationException("Emty / Invalid input.");
                }
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        // GET: Product/Details/5
        public ActionResult Details(Guid id, GetProducts ProductContext)
        {
            List <ProductModell> loadedProducts  = ProductContext.GetProduct();
            ProductModell        loadedProducts2 = new ProductModell();

            foreach (ProductModell Modell in loadedProducts)
            {
                if (Modell.productID == id)
                {
                    loadedProducts2 = Modell;
                }
            }

            return(View(loadedProducts2));
        }
Пример #3
0
        /// <summary>
        /// Validating if id of in ProductModell exist or not. Return an bool.
        /// </summary>
        /// <param name="ínputProduct"></param>
        /// <returns></returns>
        private async Task <bool> validateIDToDatabaseAsync(ProductModell ínputProduct)
        {
            try
            {
                ProductModell PruductId = await ProductsContext.Products.FindAsync(ínputProduct.productID);

                while (PruductId != null)
                {
                    return(true);
                }
            }
            catch
            {
                throw;
            }

            return(false);
        }