Example #1
0
        public void SetUp()
        {
            _recipeRepoMock      = new Mock <IDbRepository <Recipe> >();
            _userRepoMock        = new Mock <IDbRepository <User> >();
            _mappedSearchHandler = new Mock <MappedSearchHandler <Recipe> >(null);

            _recipeStore = new RecipeStore(_recipeRepoMock.Object, _userRepoMock.Object, _mappedSearchHandler.Object);
        }
        public async Task <List <MinimalRecipe> > Stared([FromHeader] string auth)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            HttpContext.Response.Headers.Add("auth", auth);
            return(await RecipeStore.GetStared(user));
        }
        public async void Unstar([FromHeader] string auth, [FromForm] long id)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            await RecipeStore.Unstar(id, user);
        }
Example #4
0
        public HomePageViewModel()
        {
            Title           = "Home";
            Days            = new ObservableCollection <Day>();
            Recipes         = new ObservableCollection <Recipe>();
            Ingredients     = new ObservableCollection <Ingredient>();
            Meals           = new ObservableCollection <Meal>();
            LoadDaysCommand = new Command(async(TargetDay) => await ExecuteLoadDaysCommand((DateTime)TargetDay));
            LoadDaysCommand.Execute(DateTime.Now);
            foreach (var day in DayStore.GetItemsAsync().Result)
            {
                Days.Add(day);
            }
            foreach (var recipe in RecipeStore.GetItemsAsync().Result)
            {
                Recipes.Add(recipe);
            }
            foreach (var ingredient in IngredientStore.GetItemsAsync().Result)
            {
                Ingredients.Add(ingredient);
            }
            foreach (var meal in MealStore.GetItemsAsync().Result)
            {
                Meals.Add(meal);
            }

            MessagingCenter.Subscribe <NewRecipePage, Recipe>(this, "AddRecipe", async(obj, recipe) =>
            {
                var newRecipe = recipe as Recipe;
                Recipes.Add(newRecipe);
                foreach (var Type in newRecipe.Types)
                {
                    foreach (var group in _allGroups)
                    {
                        if (group.RecipeGroupType == Type)
                        {
                            group.Add(newRecipe);
                        }
                    }
                }
                UpdateListContents();
                await RecipeStore.AddItemAsync(newRecipe);
            });

            MessagingCenter.Subscribe <NewIngredientPage, Ingredient>(this, "AddIngredient", async(obj, ingredient) =>
            {
                var newIngredient = ingredient as Ingredient;
                Ingredients.Add(newIngredient);
                await IngredientStore.AddItemAsync(newIngredient);
            });
        }
        public async Task <List <MinimalRecipe> > Search([FromHeader] string auth, [FromForm] string keys, [FromForm] string inventory)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            List <MinimalRecipe> list;

            HttpContext.Response.Headers.Add("auth", auth);
            if (inventory != null)
            {
                var inv = InventoryStore.Get(inventory, user).Result;
                if (inv == null)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(null);
                }

                var r = new List <Product>(inv._products);
                list = RecipeSearch.SearchMinimalRecipe(API_KEY, 10, r);
            }

            else
            {
                list = RecipeSearch.SearchMinimalRecipe(API_KEY, 10, keys);
            }

            foreach (var v in list)
            {
                await RecipeStore.Add(v);
            }

            return(list);
        }
Example #6
0
 public UserDataStore(RecipeStore recipeStore)
 {
     _recipeStore = recipeStore ?? throw new ArgumentNullException(nameof(recipeStore));
 }
 public ActionResult <ICollection <Recipe> > GetByIngredient(string ingredient)
 {
     return(Ok(RecipeStore.GetRecipesByIngredient(ingredient)));
 }
 public ActionResult <ICollection <string> > GetIngredients()
 {
     return(Ok(RecipeStore.GetAllIngredients()));
 }
 public ActionResult <ICollection <Recipe> > GetRecipes()
 {
     return(Ok(RecipeStore.GetAllRecipes()));
 }
        //private static List<Recipe> _recipes;

        public MockDataRepository(RecipeStore rs)
        {
            _rs = rs;
        }