Exemple #1
0
        /// <summary>
        /// Updates a user in the database
        /// </summary>
        /// <param name="user"></param>
        public void updateUser(string str)
        {
            masterEntities m            = ContextSingleton.getContext();
            RecipeService  recipeclient = new RecipeService();

            User user       = JsonConvert.DeserializeObject <User>(str, jsettings);
            User updateUser = JsonConvert.DeserializeObject <User>(GetUser(user.User_id), jsettings);

            updateUser.dairyfree      = user.dairyfree;
            updateUser.favJokes       = user.favJokes;
            updateUser.favTrivia      = user.favTrivia;
            updateUser.favorites      = user.favorites;
            updateUser.First_name     = user.First_name;
            updateUser.gender         = user.gender;
            updateUser.glutenfree     = user.glutenfree;
            updateUser.height         = user.height;
            updateUser.Last_name      = user.Last_name;
            updateUser.password       = user.password;
            updateUser.userName       = user.userName;
            updateUser.User_id        = user.User_id;
            updateUser.vegan          = user.vegan;
            updateUser.vegetarian     = user.vegetarian;
            updateUser.weight         = user.weight;
            m.Entry(updateUser).State = System.Data.Entity.EntityState.Modified;

            m.SaveChanges();
        }
Exemple #2
0
        public String GetFoodTrivia()
        {
            masterEntities    m           = new masterEntities();
            List <FoodTrivia> foodTrivias = new List <FoodTrivia>();
            var foodTrivialst             = from k in m.FoodTrivia select k;

            foreach (FoodTrivia ft in foodTrivialst)
            {
                foodTrivias.Add(ft);
            }
            return(JsonConvert.SerializeObject(foodTrivias));
        }
Exemple #3
0
        /// <summary>
        /// Finds a user in the databse by username
        /// </summary>
        /// <param name="username"></param>
        /// <returns>Returns a user object</returns>
        public User FindUserByUsername(string username)
        {
            masterEntities m       = ContextSingleton.getContext();
            var            userlst = from k in m.User where k.userName.Equals(username) select k;

            foreach (var usr in userlst)
            {
                Console.WriteLine(usr.First_name);
                return(usr);
            }
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Get one recipe based on recipe name.
        /// </summary>
        /// <param name="recipe_name">Name of desired recipe</param>
        /// <returns>JSON-string representing recipe</returns>
        public String findRecipesByName(String recipe_name)
        {
            masterEntities m         = ContextSingleton.getContext();
            List <Recipe>  recipes   = new List <Recipe>();
            var            Recipelst = from k in m.Recipe where k.Recipe_name == recipe_name select k;

            foreach (Recipe recipe in Recipelst)
            {
                recipes.Add(recipe);
            }
            return(JsonConvert.SerializeObject(recipes, jsettings));
        }
Exemple #5
0
        /// <summary>
        /// Get one recipe based on recipe id.
        /// </summary>
        /// <param name="recipe_id">Id of desired recipe</param>
        /// <returns>JSON-string representing recipe</returns>
        public String findRecipesById(int recipe_id)
        {
            masterEntities m         = ContextSingleton.getContext();
            var            RecipeDtb = from k in m.Recipe where k.Recipe_id == recipe_id select k;

            foreach (Recipe rcp in RecipeDtb)
            {
                return(JsonConvert.SerializeObject(rcp, jsettings));
            }

            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Fetches all recipe from database
        /// </summary>
        /// <returns>JSON string representing a list of all recipes</returns>
        public string getAllRecipes()
        {
            masterEntities m          = ContextSingleton.getContext();
            List <Recipe>  recipes    = new List <Recipe>();
            var            recipelist = from k in m.Recipe select k;

            foreach (Recipe recipe in recipelist)
            {
                recipes.Add(recipe);
            }
            return(JsonConvert.SerializeObject(recipes, jsettings));
        }
Exemple #7
0
        public String GetFoodJoke()
        {
            masterEntities  m           = new masterEntities();
            List <FoodJoke> foodJokes   = new List <FoodJoke>();
            var             foodJokelst = from k in m.FoodJoke select k;

            foreach (var fj in foodJokelst)
            {
                foodJokes.Add(fj);
            }
            return(JsonConvert.SerializeObject(foodJokes));
        }
Exemple #8
0
        /// <summary>
        /// Gets one user from backend
        /// </summary>
        /// <param name="value">Id of the desired </param>
        /// <returns></returns>
        public string GetUser(int value)
        {
            masterEntities m       = ContextSingleton.getContext();
            var            userlst = from k in m.User where k.User_id == value select k;
            var            user    = new User();

            foreach (var usr in userlst)
            {
                user = usr;
            }
            m.Entry(user).State = System.Data.Entity.EntityState.Detached;
            return(JsonConvert.SerializeObject(user, jsettings));
        }
Exemple #9
0
        /// <summary>
        /// Fetches one recipe from database based on id.
        /// </summary>
        /// <param name="id">Id of the desired recipe</param>
        /// <returns>One recipe object</returns>
        public Recipe getRecipe(int id)
        {
            masterEntities m         = ContextSingleton.getContext();
            var            Recipelst = from k in m.Recipe where k.Recipe_id == id select k;
            var            recipe    = new Recipe();

            foreach (var rcp in Recipelst)
            {
                recipe = rcp;
            }
            m.Entry(recipe).State = System.Data.Entity.EntityState.Detached;
            return(recipe);
        }
Exemple #10
0
        /// <summary>
        /// Checks a username a password againts the database
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns>A status </returns>
        public int verifyUser(string userName, string password)
        {
            masterEntities m       = ContextSingleton.getContext();
            var            userlst = from k in m.User where k.userName.Equals(userName) select k;

            foreach (var usr in userlst)
            {
                if (usr.password.Equals(password))
                {
                    return(usr.User_id);
                }
                else
                {
                    return(-2);
                }
            }
            return(-1);
        }
Exemple #11
0
        /// <summary>
        /// Adds a user to the database
        /// </summary>
        /// <param name="first_name"></param>
        /// <param name="last_name"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="weight"></param>
        /// <param name="height"></param>
        /// <param name="vegetarian"></param>
        /// <param name="vegan"></param>
        /// <param name="dairyfree"></param>
        /// <param name="glutenfree"></param>
        /// <param name="gender"></param>
        public void AddUser(string first_name, string last_name, string username, string password, double?weight, double?height, bool?vegetarian, bool?vegan, bool?dairyfree, bool?glutenfree, bool?gender)
        {
            masterEntities m       = ContextSingleton.getContext();
            User           newUser = new User();

            newUser.First_name = first_name;
            newUser.Last_name  = last_name;
            newUser.userName   = username;
            newUser.password   = password;
            newUser.weight     = weight;
            newUser.height     = height;
            newUser.vegetarian = vegetarian;
            newUser.vegan      = vegan;
            newUser.dairyfree  = dairyfree;
            newUser.glutenfree = glutenfree;
            newUser.gender     = gender;
            m.User.Add(newUser);
            m.SaveChanges();
        }
Exemple #12
0
        /// <summary>
        /// Uses a super complex alorithm to perform an advanced search Query in the remote databases
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <param name="vegetarian"></param>
        /// <param name="vegan"></param>
        /// <param name="cheap"></param>
        /// <param name="glutenfree"></param>
        /// <param name="dairyfree"></param>
        /// <param name="maxminues"></param>
        /// <returns>Returns a list of all the recipes matching all the terms</returns>
        public string getRecipesAdvanced(string searchTerm, bool vegetarian, bool vegan, bool cheap, bool glutenfree, bool dairyfree, int maxminues)
        {
            masterEntities m          = ContextSingleton.getContext();
            List <Recipe>  recipes    = new List <Recipe>();
            var            recipelist = from k in m.Recipe select k;

            foreach (Recipe recipe in recipelist)
            {
                if (!String.IsNullOrEmpty(searchTerm))
                {
                    if (!recipe.Recipe_name.ToLower().Contains(searchTerm.ToLower()))
                    {
                        continue;
                    }
                }
                if (vegetarian == true && recipe.Recipe_veg == false)
                {
                    continue;
                }
                if (vegan == true && recipe.Recipe_vegan == false)
                {
                    continue;
                }
                if (cheap == true && recipe.cheap == false)
                {
                    continue;
                }
                if (glutenfree == true && recipe.glutenfree == false)
                {
                    continue;
                }
                if (dairyfree == true && recipe.dairyfree == false)
                {
                    continue;
                }
                if (maxminues < recipe.Recipe_minutes && maxminues != 0)
                {
                    continue;
                }
                recipes.Add(recipe);
            }
            return(JsonConvert.SerializeObject(recipes, jsettings));
        }
Exemple #13
0
        /// <summary>
        /// Adds one recipe to database.
        /// </summary>
        /// <param name="recipe_id"></param>
        /// <param name="recipe_name"></param>
        /// <param name="recipe_minutes"></param>
        /// <param name="recipe_veg"></param>
        /// <param name="recipe_vegan"></param>
        /// <param name="cheap"></param>
        /// <param name="sustainable"></param>
        /// <param name="glutenfree"></param>
        /// <param name="dairyfree"></param>
        /// <param name="image"></param>
        /// <param name="instruction"></param>
        /// <param name="imageTyp"></param>
        /// <param name="ingredientList"></param>
        public void addRecipe(int recipe_id, String recipe_name, int recipe_minutes, Boolean recipe_veg,
                              Boolean recipe_vegan, Boolean cheap, Boolean sustainable, Boolean glutenfree, Boolean dairyfree,
                              String image, String instruction, String imageTyp, List <Ingredients> ingredientList)
        {
            masterEntities m   = ContextSingleton.getContext();
            Recipe         rcp = new Recipe();

            rcp.Recipe_id      = recipe_id;
            rcp.Recipe_name    = recipe_name;
            rcp.Recipe_minutes = recipe_minutes;
            rcp.Recipe_veg     = recipe_veg;
            rcp.Recipe_vegan   = recipe_vegan;
            rcp.cheap          = cheap;
            rcp.sustainable    = sustainable;
            rcp.glutenfree     = glutenfree;
            rcp.dairyfree      = dairyfree;
            rcp.image          = image;
            rcp.Instructions   = instruction;
            rcp.imageTyp       = imageTyp;
            rcp.Ingredients    = ingredientList;
            m.Recipe.Add(rcp);
            m.SaveChanges();
        }