コード例 #1
0
        /// <summary author="Jared Greenfield" created="2019/01/23">
        /// Retrieves a list of all Items.
        /// </summary>
        /// <exception cref="SQLException">Insert Fails (example of exception tag)</exception>
        /// <returns>List of all Items</returns>
        public List <Item> RetrieveAllItems()
        {
            List <Item> items = new List <Item>();

            try
            {
                items = _itemAccessor.SelectAllItems();
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(items);
        }
コード例 #2
0
        /// <summary>
        /// Jared Greenfield
        /// Created: 2018/01/29
        ///
        /// Creates a recipe line under the given ID.
        /// </summary>
        /// <param name="recipeID">The ID of the recipe that the line will be listed under.</param>
        /// <param name="line">The recipe line to be added.</param>
        /// <exception cref="SQLException">Insert Fails (example of exception tag)</exception>
        /// <returns>1 if successful, 0 if unsuccessful</returns>
        public List <RecipeItemLineVM> SelectRecipeLinesByID(int recipeID)
        {
            List <RecipeItemLineVM> lines = new List <RecipeItemLineVM>();
            var         conn    = DBConnection.GetDbConnection();
            string      cmdText = @"sp_select_recipe_item_lines";
            List <Item> items   = new List <Item>();

            try
            {
                items = _itemAccessor.SelectAllItems();
                SqlCommand cmd1 = new SqlCommand(cmdText, conn);
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@RecipeID", recipeID);
                try
                {
                    conn.Open();
                    var reader = cmd1.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int              itemID        = reader.GetInt32(1);
                            decimal          quantity      = reader.GetDecimal(2);
                            string           unitOfMeasure = reader.GetString(3);
                            var              item          = items.Find(x => x.ItemID == itemID);
                            string           itemName      = item.Name;
                            RecipeItemLineVM line          = new RecipeItemLineVM(itemID, recipeID, itemName, quantity, unitOfMeasure);
                            lines.Add(line);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(lines);
        }