Ejemplo n.º 1
0
        /// <summary>
        /// Rhett Allen
        /// Created Date: 3/31/16
        /// Counts how many recipes are in the database with a category and contain a similar keyword
        /// </summary>
        /// <param name="keyword">Word that is contained in the recipe fields</param>
        /// <param name="category">The recipe's category</param>
        /// <returns>Number of recipes in the database with specified category and contain a similar keyword</returns>
        public int GetRecipesCount(string keyword, string category)
        {
            int count = 0;

            try
            {
                count = RecipeAccessor.RetrieveRecipeCount(keyword, category);
                return(count);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Recipes could not be retrieved: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void ParseIngridients()
        {
            var json = File.ReadAllText(@"..\..\" + "CsvTest.Products.approved.txt");
            var products = JsonConvert.DeserializeObject<List<Product>>(json).Skip(1).ToList();
            //var chickenbreasts = products.Where(p => p.Name == "chicken breasts");
            //products = chickenbreasts.Concat(products).ToList();
            products.Single(p => p.Name == "tomato").Synonyms += ",Томаты".ToLower();

            var text = @"Ingredients
            4 boneless, skinless chicken breasts
            4 boneless, skinless chicken breast
            ½ cup Dijon mustard
            ¼ cup maple syrup
            1 tablespoon red wine vinegar
            Salt & pepper
            Fresh rosemary

            Томаты очищенные сливовидные в собственном соку — 660 г
            Помидорки черри — 500 г
            Паста сухая — 100 г
            Сливочное масло — 150 г
            Тимьян свежий — 1 веточка
            Базилик зеленый — 1 пучок
            Сахар — 40 г
            Оливковое масло — 50 мл
            Пеперончино
            Морская соль
            Чеснок — 2 зубчика
            ";

            //            text = @"
            //Томаты очищенные сливовидные в собственном соку — 660 г
            //Помидорки черри — 500 г";

            var sb = new StringBuilder();
            var accessor = new RecipeAccessor((IDbConnection) null);
            var rs = accessor.ParseIngridients(text, products);
            foreach (var r in rs)
            {
                sb.AppendLine(r.Id + " " + r.Description + " " + r.ProductId + " " + r.Name);
            }

            Approvals.Verify(sb.ToString());
        }
Ejemplo n.º 3
0
        ///<summary>
        ///Author: Chris Schwebach
        ///Recipe logic for user parameter input to insert a recipe
        ///Date: 3/19/16
        ///</summary>
        public bool AddNewRecipe(string title, string category, string directions, int userId)
        {
            bool result = true;

            var newRecipe = new Recipe()
            {
                Title      = title,
                Category   = category,
                Directions = directions
            };

            if (title.Length < 1 || title.Length > 50)
            {
                throw new ApplicationException("Title for the recipe is required! Must Be less than 50 characters in length");
            }
            else if (category.Length < 1)
            {
                throw new ApplicationException("Must choose a category!");
            }
            else if (directions.Length < 1)
            {
                throw new ApplicationException("Ingredients and directions are required!");
            }

            try
            {
                if (RecipeAccessor.CreateRecipe(newRecipe, userId) == 1)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Invalid Input!");
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rhett Allen
        /// Created Date: 3/31/16
        /// Gets a list of recipes based on the category and keyword search
        /// </summary>
        /// <param name="keyword">Word that is contained in the recipe fields</param>
        /// <param name="category">The recipe's category</param>
        /// <param name="pageNumber">The page number of the datagrid for recipes. Used to create the offset.</param>
        /// <param name="perPage">The number of recipes displayed per page.</param>
        /// <returns>List of recipes based on the category and keyword search</returns>
        public List <Recipe> GetRecipesWithKeywordAndCategory(string keyword, string category, int pageNumber, int perPage)
        {
            List <Recipe> recipes = new List <Recipe>();

            int offset = (pageNumber - 1) * perPage;

            try
            {
                recipes = RecipeAccessor.RetrieveRecipesWithKeywordAndCategory(keyword, category, offset, perPage);

                if (recipes.Count > 0)
                {
                    return(recipes);
                }
                else
                {
                    throw new ApplicationException("No recipes found");
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Recipes could not be retrieved");
            }
        }
Ejemplo n.º 5
0
 public void ReadRecipes()
 {
     var dbFile = @"d:\work\Ricettario\Ricettario\App_Data\db.sqlite";
     var factory = new OrmLiteConnectionFactory(dbFile, SqliteDialect.Provider);
     var accessor = new RecipeAccessor(factory);
     var recipe = accessor.GetById(1);
     Console.WriteLine(recipe.Name);
     Console.WriteLine(recipe.Ingredients);
 }