Example #1
0
        public IActionResult AddOCRToRec()
        {
            // Laver et RecipeDb objekt med de værdier fundet igennem OCR
            RecipeDb recipe = new RecipeDb(TempData["Title"] as string, TempData["Description"] as string, TempData["Ingredients"] as string, TempData["Steps"] as string);

            return(View("../Recipe/Addrecipe", recipe));
        }
Example #2
0
        public IActionResult EditResult(string id, RecipeDb rDb, string save)
        {
            if (id != rDb.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                switch (save)
                {
                case "Save Recipe":
                    tCrud.Update(rDb, id);
                    break;

                case "Save as new":
                    rDb.Id = GetRandomHexNumber(24);
                    tCrud.AddRecipe(rDb);
                    break;
                }
                // rDbService.Update(id, rDb);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(rDb));
            }
        }
Example #3
0
        public IActionResult NewRecipe(RecipeDb recDb)
        {
            if (ModelState.IsValid)
            {
                rDbService.Create(recDb);
                return(RedirectToAction(nameof(Index)));
            }

            return(View("AddRecipe", recDb));
        }
Example #4
0
        public IActionResult AddRecToUser(RecipeDb rDb)
        {
            if (ModelState.IsValid)
            {
                rDb.Id = GetRandomHexNumber(24);
                tCrud.AddRecipe(rDb);
                return(View("Index", tCrud.GetRecipes()));
            }

            return(View("AddRecipe", rDb));
        }
Example #5
0
        public string CheckFav(RecipeDb rDb, string id)
        {
            int favIndex = user.favorites.FindIndex(i => i.Id == id);

            if (favIndex >= 0)
            {
                user.favorites.Add(rDb);
                return($"{rDb.Name} has been added to favorites");
            }
            else
            {
                user.favorites.Remove(rDb);
                return($"{rDb.Name} has been removed from favorites");
            }
        }
Example #6
0
        public RecipeDb Update(RecipeDb rDb, string id)
        {
            RecipeDb x     = user.recipeDbs.First(i => i.Id == id);
            var      index = user.recipeDbs.IndexOf(x);

            // Vend tilbage senere
            if (index != -1)
            {
                testing.FindOneAndUpdate(Builders <TestUser> .Filter.Eq("Id", user.Id), Builders <TestUser> .Update.Pull("Recipes", id));
                string a = GetRandomHexNumber(24);
                testing.FindOneAndUpdate(Builders <TestUser> .Filter.Eq("Id", user.Id), Builders <TestUser> .Update.AddToSet("Recipes", a));
            }
            int favIndex = user.favorites.FindIndex(i => i.Id == id);

            if (favIndex >= 0)
            {
                user.favorites[favIndex] = rDb;
            }
            return(rDb);
        }
 public void Update(string id, RecipeDb recDbIn)
 {
     recipes.ReplaceOne(rec => rec.Id == id, recDbIn);
 }
 public RecipeDb Create(RecipeDb recDb)
 {
     recipes.InsertOne(recDb);
     return(recDb);
 }
Example #9
0
 // Fjern opskrift (Ikke brugt i projektet noget sted)
 public void Remove(RecipeDb recDbIn)
 {
     recipes.DeleteOne(rec => rec.Id == recDbIn.Id);
 }
Example #10
0
 public IngredientRepository(RecipeDb db)
 {
     _db = db;
 }
Example #11
0
 public RecipeRepository(RecipeDb db, IMapper mapper)
 {
     _db     = db;
     _mapper = mapper;
 }
Example #12
0
        public TestUser AddRecipe(RecipeDb rDb)
        {
            user = testing.FindOneAndUpdate(Builders <TestUser> .Filter.Eq("Id", user.Id), Builders <TestUser> .Update.AddToSet("Recipes", rDb));

            return(user);
        }