public UpdateRecipe(int RecipeId)
 {
     rc = new RecipeCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);
     InitializeComponent();
     recipe = GetRecipeById(RecipeId);
     SetData();
 }
Beispiel #2
0
        public ActionResult SubmitCreate(RecipeModel rm)
        {
            RecipeCaller rc = new RecipeCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);

            RecipeDTO recipeToBeCreated = new RecipeDTO();

            recipeToBeCreated.Title = rm.Title;
            recipeToBeCreated.User  = new UserDTO()
            {
                Id = 1
            };
            recipeToBeCreated.Instruction     = rm.Instruction;
            recipeToBeCreated.IngredientLines = new List <IngredientLineDTO>();
            recipeToBeCreated.Images          = new List <ImageDTO>();

            if (rm.IngredientLines != null)
            {
                foreach (var item in rm.IngredientLines)
                {
                    IngredientLineDTO lineDTO = new IngredientLineDTO();
                    lineDTO.Ingredient = new IngredientDTO()
                    {
                        Name = item.Ingredient.Name
                    };
                    lineDTO.Amount          = item.Amount;
                    lineDTO.MeasureUnitText = item.MeasureUnit;

                    recipeToBeCreated.IngredientLines.Add(lineDTO);
                }
            }
            if (rm.Images != null)
            {
                foreach (var item in rm.Images)
                {
                    ImageDTO image = new ImageDTO();
                    image.FileName = item.FileName;

                    recipeToBeCreated.Images.Add(image);
                }
            }

            RFApiResult response = rc.CreateRecipe(recipeToBeCreated);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                SetFlash(FlashMessageType.Success, response.Message);
            }
            else
            {
                SetFlash(FlashMessageType.Danger, response.Message);
            }

            return(Redirect(Url.Action("Index", "Home")));
        }
Beispiel #3
0
        public ActionResult ViewRecipe(string id)
        {
            RecipeCaller rc = new RecipeCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);

            RecipeModel recipe = rc.FindBySlug(id);

            if (recipe.StatusCode == HttpStatusCode.OK)
            {
                ViewBag.recipe = recipe;
                return(View());
            }

            return(HttpNotFound());
        }
Beispiel #4
0
        private List <RecipeModel> GetAllRecipes()
        {
            RecipeCaller rc = new RecipeCaller("https://localhost:44320/api");

            return(rc.GetAll().recipes);
        }
        private List <RecipeModel> GetAllRecipes()
        {
            RecipeCaller rc = new RecipeCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);

            return(rc.GetAll().recipes);
        }