public int CreateProduct(ProductModel pm)
        {
            int result = DaoUtilities.NO_CHANGES;

            PRODUCT p = db.PRODUCT.Create();

            p.PRODUCT_ID = pm.ProductId;
            p.PRODUCT_NAME = pm.Name;
            p.PRODUCT_DESCRIPTION = pm.Description;
            p.PRODUCT_AVAILABLEQUANTITY = pm.AvailableQuantity;
            p.PRODUCT_MEMBERREDUCTION = pm.MemberReduction;
            p.PRODUCT_CAT = pm.CategoryId;
            p.PRODUCT_USERID = pm.UserId;
            p.PRODUCT_PRICE = pm.Price;

            db.PRODUCT.Add(p);
            try
            {
                int saveResult = db.SaveChanges();

                if (saveResult == 1)
                    result = DaoUtilities.SAVE_SUCCESSFUL;
            }
            catch (DbUpdateConcurrencyException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UPDATE_EXCEPTION;
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
            }
            catch (NotSupportedException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UNSUPPORTED_EXCEPTION;
            }
            catch (ObjectDisposedException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.DISPOSED_EXCEPTION;
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
            }
            return result;
        }
        public int DeleteProduct(ProductModel pm)
        {
            int result = DaoUtilities.NO_CHANGES;

            PRODUCT p = db.PRODUCT.Find(pm.ProductId);

            if (p != null)
            {
                db.PRODUCT.Remove(p);
                try
                {
                    int saveResult = db.SaveChanges();

                    if (saveResult == 1)
                        result = DaoUtilities.SAVE_SUCCESSFUL;
                }
                catch (DbUpdateConcurrencyException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_EXCEPTION;
                }
                catch (DbEntityValidationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UNSUPPORTED_EXCEPTION;
                }
                catch (ObjectDisposedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.DISPOSED_EXCEPTION;
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
                }
            }

            return result;
        }
        /// <summary>
        /// Convert a product from the database to a ProductModel
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public ProductModel ConvertProductToProductModel(PRODUCT p)
        {
            ProductModel pm = new ProductModel();

            if (p != null)
            {
                pm.ProductId = p.PRODUCT_ID;
                pm.Name = p.PRODUCT_NAME;
                pm.Description = p.PRODUCT_DESCRIPTION;
                pm.AvailableQuantity = p.PRODUCT_AVAILABLEQUANTITY;
                pm.MemberReduction = p.PRODUCT_MEMBERREDUCTION;
                pm.CategoryId = p.PRODUCT_CAT;
                pm.UserId = p.PRODUCT_USERID;
                pm.Price = p.PRODUCT_PRICE;
            }
            else
                pm = null;

            return pm;
        }