Esempio n. 1
0
        // Method which is used to take User data from the AdminCrud page and sends it through a method call to DAL to be inserted in the database.
        // Returns a bool to be used to tell the Admin user if the product was created successfully.
        #region CreateProduct
        public bool CreateProduct(string pType, string pName, double price, string pDescription, string imagePath)
        {
            bool    successfull = true;
            Product p           = null;

            #region MessageToAdmin
            if ((pType == null || pType.Trim().Length == 0) ||
                (pName == null || pName.Trim().Length == 0) ||
                (price == 99999) ||
                (pDescription == null || pDescription.Trim().Length == 0))
            {
                successfull = false;
            }
            #endregion MessageToAdmin

            // Only objects of the Food class has an imgPath.
            if (imagePath != null && imagePath.Trim().Length > 0)
            {
                p = new Food(pType, pName, price, pDescription, imagePath);
            }
            else
            {
                p = new Drinks(pType, pName, price, pDescription);
            }

            successfull = DAL.CreateProduct(p);
            return(successfull);
        }
Esempio n. 2
0
        // Returns a list of Drinks/Beverages from the database to be displayed on the menu page (through the productmanager).
        #region GetBeverages
        public static List <Drinks> GetBeverages()
        {
            List <Drinks> allBeverages = new List <Drinks>();

            using (SqlConnection connection = new SqlConnection(conn))
            {
                connection.Open();
                SqlCommand    cmd = new SqlCommand(@"DECLARE @return_value int
                                                EXEC @return_value = [dbo].[SP_ProductGetBeverages]", connection);
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    string  pName        = (string)rdr["PName"];
                    decimal price        = (decimal)rdr["price"];
                    string  pDescription = (string)rdr["PDescription"];

                    Drinks d = new Drinks(pName, Convert.ToDouble(price), pDescription);
                    allBeverages.Add(d);
                }
            }
            return(allBeverages);
        }