Example #1
0
        // Accepts the user input (id, name, pack, price, availability) and adds the item
        // to the database
        public void AddToDB(string Uid, string Uname, string Upack, decimal Uprice, bool Uactive)
        {
            bevToAdd.id     = Uid;
            bevToAdd.name   = Uname;
            bevToAdd.pack   = Upack;
            bevToAdd.price  = Uprice;
            bevToAdd.active = Uactive;

            // Try to add the item, if it fails remove it and display
            // an error message
            try
            {
                bevEntities.Beverages.Add(bevToAdd);

                bevEntities.SaveChanges();
            }
            catch
            {
                UserInterface.DisplayAddError();
                bevEntities.Beverages.Remove(bevToAdd);
            }
        }