Ejemplo n.º 1
0
        ///<summary>
        ////Add new Product
        ///<param>Product</param>
        ///</summary>
        public async Task <Product> AddProduct(Product item)
        {
            try
            {
                item.Id = Guid.NewGuid();
                db.Products.Add(item);
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException dbAddException)
            {
                if (ProductExists(item.Id))
                {
                    throw new Exception("Product with same Id already exists.");
                }
                else
                {
                    throw dbAddException;
                }
            }

            return(item);
        }