// GET: Recipes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var recipe = await _context.Recipe
                         .Include(r => r.Level)
                         .FirstOrDefaultAsync(m => m.RecipeId == id);

            if (recipe == null)
            {
                return(NotFound());
            }

            RecipeVM recipeVM = new RecipeVM();

            recipeVM.Recipe = recipe;

            var steps = await _context.Steps
                        .Where(m => m.RecipeId == id)
                        .ToListAsync();

            recipeVM.Steps = steps;

            var ingredients = await _context.Ingredient
                              .Where(m => m.RecipeId == id)
                              .ToListAsync();

            recipeVM.Ingredient = ingredients;

            return(View(recipeVM));
        }
Ejemplo n.º 2
0
        public AddRecipeViewModel()
        {
            StepIngredList  = new ObservableCollection <RecipeStepIngredientVM>();
            IngredientsList = new ObservableCollection <IngredientListVM>();
            Keywords        = new ObservableCollection <Keyword>();

            NewUserRcpFav = new UserRecipeFavorite()
            {
                UserId   = userDetailsID,
                Favorite = false,
                RecipeId = 0
            };

            NewRcp = new RecipeVM()
            {
                RecipeName  = "",
                Description = "",
                OwnerId     = userDetailsID,
                Shared      = false,
                Notes       = "",
                //MyRating = 0,
                //ShareRating = 0,
                //NumShareRatings = 0,
                RecipePic = "",
                //PrepTime = 0,
                //CookTime = 0,
                ServingSize = ""
            };
        }
Ejemplo n.º 3
0
        public IActionResult Add3(RecipeVM vm)
        {
            // Get the current values from Session
            Recipe recipeInProgress = GetRecipeInProgress();

            // Validate the fields that are on this form.  If they're no good, no sense in continuing
            string[] fieldsToValidate =
            {
                "Recipe.Steps",
            };
            if (AnyInvalid(fieldsToValidate))
            {
                // If there are any validation errors, re-show the view to the user
                vm.Recipe = recipeInProgress;
                CreateSelectLists(vm);
                return(View(vm));
            }

            // Apply values from this view to the one in the cart
            recipeInProgress.Steps = vm.Recipe.Steps;

            // Save the recipe
            int recipeId = recipeDAO.CreateRecipe(recipeInProgress);

            // Clear the Session recipe
            ClearRecipeInProgress();

            // Go to the next view
            return(RedirectToAction("AddConfirmation", "Recipe", new { id = recipeId }));
        }
Ejemplo n.º 4
0
        public CreateRecipe(RecipeVM recipeVm, Recipe recipe)
        {
            _recipeVm = recipeVm;
            InitializeComponent();


            RecipeCategoryDropdown.ItemsSource   = _recipeVm.GetRecipeCategories();
            RecipeCategoryDropdown.SelectedIndex = 0;
            ComboBoxUnit.SelectedIndex           = 0;


            var commodities = _recipeVm.GetCommodities();

            var commodityNames = commodities.Select(commodity => commodity.Name).ToList();

            CommodityName.ItemsSource = commodityNames;

            if (recipe != null)
            {
                _editState  = true;
                _editRecipe = recipe;
                // Loading information from already existing commodity.
                var recipeCategory = _recipeVm.GetRecipeCategory(recipe).RecipeCategory;
                RecipeCategoryDropdown.SelectedItem = recipeCategory;

                _shawdowCommodities = _recipeVm.GetCommoditiesFromRecipe(recipe);

                ListBoxCommodities.ItemsSource = _shawdowCommodities;
                ListBoxCommodities.Items.Refresh();

                Description.Text = recipe.Description;
                RecipeName.Text  = recipe.Name;
            }
        }
Ejemplo n.º 5
0
        // GET: Recipe/Edit/5
        public async Task <IActionResult> Edit(Guid Id)
        {
            Recipe recipe = await _recipeService.Get(Id);

            RecipeVM model = _recipeMapper.ToViewModel(recipe);

            return(View(model));
        }
Ejemplo n.º 6
0
        public async Task <RecipeVM> SaveRecipe(RecipeVM recipeVm)
        {
            var recipeDto = recipeVm.ToDto();

            _recipeRepository.AddItem(recipeDto);
            await _unitOfWork.SubmitChanges();

            return(recipeDto.ToVM());
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            RecipeVM model = recipeProcessor.Get(id).DTOToViewModel(MapRecipe);

            sessionManager.SetItem(new ItemInfo()
            {
                Name = model.Name
            });
            return(View(model));
        }
Ejemplo n.º 8
0
        public IActionResult Add3()
        {
            // Get the current values from Session
            Recipe   recipe = GetRecipeInProgress();
            RecipeVM vm     = new RecipeVM()
            {
                Recipe = recipe
            };

            CreateSelectLists(vm);
            return(View(vm));
        }
Ejemplo n.º 9
0
 public ActionResult Edit(RecipeVM recipe)
 {
     if (ModelState.IsValid)
     {
         recipeProcessor.Update(mapper.Map <RecipeDTO>(recipe));
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(recipe));
     }
 }
Ejemplo n.º 10
0
 public IActionResult Edit(RecipeVM recipeVM)
 {
     try
     {
         Recipe recipe = _recipeMapper.ToModel(recipeVM);
         _recipeService.Update(recipe);
         return(RedirectToAction("List"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 11
0
        public List <Recipe> GetAllRecipes()
        {
            RecipeVM vm = new RecipeVM();

            using (ApplicationDbContext ctx = new ApplicationDbContext())
            {
                var query = from e in ctx.Recipe
                            select e;

                vm.recipes = query.ToList();
            }
            return(vm.recipes);
        }
 public MainFeed()
 {
     InitializeComponent();
     vM = new RecipeVM();
     try
     {
         ListPosts.ItemsSource = Client.getInstance().getFeedIL();
     }
     catch
     {
         //null pointer de cuando no hay feed aun
     }
 }
        public IActionResult Recipes(int id)
        {
            List <Recipe>     _recepies    = new List <Recipe>();
            List <RecipeType> _recipeTypes = new List <RecipeType>();
            RecipeVM          vm           = new RecipeVM();

            if (id <= 0)
            {
                try
                {
                    using (ApplicationDbContext ctx = new ApplicationDbContext())
                    {
                        _recepies = ctx.Recipe
                                    .ToList();
                        _recipeTypes = ctx.RecipeType
                                       .ToList();
                    }

                    vm.recipes     = _recepies;
                    vm.recipeTypes = _recipeTypes;

                    return(View(vm));
                }
                catch (Exception e)
                {
                    return(Content("Failed loading recepies: " + e));
                }
            }

            try
            {
                using (ApplicationDbContext ctx = new ApplicationDbContext())
                {
                    _recipeTypes = ctx.RecipeType
                                   .ToList();
                    _recepies = ctx.Recipe.Where(x => x.RecipeTypeId == id)
                                .ToList();
                }

                vm.recipes     = _recepies;
                vm.recipeTypes = _recipeTypes;

                return(View(vm));
            }
            catch (Exception e)
            {
                return(Content("Failed loading recepies: " + e));
            }
        }
Ejemplo n.º 14
0
        public static RecipeDto ToDto(this RecipeVM vm)
        {
            RecipeDto dto = new RecipeDto
            {
                RecipeId     = vm.RecipeId,
                Description  = vm.Description.CleanFromHTML().EncodeSpecialCharacters(),
                CreationDate = DateTime.UtcNow,
                Title        = vm.Title.CleanFromHTML().EncodeSpecialCharacters(),
                CookTime     = vm.CookTime,
                Versions     = null,
                Details      = vm.StepDetails.Select(x => x.ToDto()).ToList(),
                Ingredients  = vm.Ingredients.Select(x => x.ToDto()).ToList()
            };

            return(dto);
        }
Ejemplo n.º 15
0
        public static RecipeVM ToVM(this RecipeDto dto)
        {
            RecipeVM recipeVm = new RecipeVM
            {
                RecipeId     = dto.RecipeId,
                Title        = dto.Title.DecodeSpecialCharacters(),
                Description  = dto.Description.DecodeSpecialCharacters(),
                CookTime     = dto.CookTime,
                CreationTime = dto.CreationDate,
                Ingredients  = dto.Ingredients.Select(x => x.ToVM()).ToList(),
                StepDetails  = dto.Details.Select(x => x.ToVM()).ToList(),
                Versions     = dto.Versions != null?dto.Versions.Select(x => x.ToVM()).ToList() : null
            };

            return(recipeVm);
        }
Ejemplo n.º 16
0
 public ActionResult Create(RecipeVM recipe)
 {
     if (ModelState.IsValid)
     {
         int id = recipeProcessor.Create(mapper.Map <RecipeDTO>(recipe));
         sessionManager.SetItem(new ItemInfo()
         {
             Name = recipe.Name
         });
         return(RedirectToAction(nameof(Cuisines), new { id }));
     }
     else
     {
         return(View());
     }
 }
Ejemplo n.º 17
0
        public RecipeVM Get(int id)
        {
            var recipeFromDb = _adminRecipeService.GetRecipeById(id);
            var model        = new RecipeVM();

            _mapper.Map(recipeFromDb, model);

            // get image from azure
            if (model.ImageUrl != null)
            {
                var base64 = _adminRecipeService.GetBase64RecipeImage(model.ImageUrl);
                model.ImageFile = base64;
            }

            return(model);
        }
Ejemplo n.º 18
0
        public IActionResult Add()
        {
            // Get any recipe in-progress
            Recipe recipe = GetRecipeInProgress();

            // Create and Initialize the ViewModel to be used in the View
            RecipeVM vm = new RecipeVM()
            {
                Recipe = recipe
            };

            // Set the SelectList values in the ViewModel (Cuisine, MealType, UOM)
            CreateSelectLists(vm);

            // Invoke the View
            return(View(vm));
        }
Ejemplo n.º 19
0
        public List <RecipeVM> GetMatchingRecipes(User user)
        {
            var recipevmsToReturn = new List <RecipeVM>();
            var recipes           = GetAllRecipes();
            var useritems         = new List <FoodItem>();

            foreach (var item in user.UserFoodItem)
            {
                useritems.Add(item.FoodItem);
            }

            foreach (var recipe in recipes)
            {
                var recipeingredients = GetFoodItemForRecipe(recipe);
                var listOfFoodMatches = new List <FoodMatching>();

                foreach (var ingredient in recipeingredients)
                {
                    bool match = false;

                    foreach (var useritem in useritems)
                    {
                        if (ingredient.FoodItem.Name == useritem.Name)
                        {
                            match = true;
                            break;
                        }
                    }

                    var foodmatch = new FoodMatching(match, ingredient.FoodItem.Name, recipe.Id);
                    listOfFoodMatches.Add(foodmatch);
                }

                double matchpercentage = GetMatchPercentage(listOfFoodMatches);

                var recipevm = new RecipeVM(recipe.Id, recipe.Title, recipe.Portions, recipeingredients, listOfFoodMatches, matchpercentage, recipe.Instructions, recipe.ImageUrl, recipe.CookingTime);
                var expiringUserIngredient = CheckExpiringUserFoodItems(user);

                recipevm.ExpiringUserIngredients = expiringUserIngredient;
                recipevmsToReturn.Add(recipevm);
            }

            var sortedList = recipevmsToReturn.OrderByDescending(p => p.MatchPercentage).ToList();

            return(sortedList);
        }
        public async Task <IActionResult> Index()
        {
            var             onlineHubContext = _context.Recipe.Include(r => r.Level);
            List <RecipeVM> recipeVMs        = new List <RecipeVM>();

            foreach (Recipe recipes in onlineHubContext)
            {
                RecipeVM recipeVM = new RecipeVM();
                recipeVM.Recipe = recipes;

                recipeVM.Steps      = _context.Steps.Where(s => s.RecipeId == recipes.RecipeId);
                recipeVM.Ingredient = _context.Ingredient.Where(s => s.RecipeId == recipes.RecipeId);

                recipeVMs.Add(recipeVM);
            }
            return(View(recipeVMs));
        }
        public IActionResult Add(RecipeVM vm)
        {
            // Get the current values from Session
            Recipe recipeInProgress = GetRecipeInProgress();

            // Set the SelectList values in the ViewModel (Cuisine, MealType, UOM)
            CreateSelectLists(vm);

            // Validate the fields that are on this form.  If they're no good, no sense in continuing
            string[] fieldsToValidate =
            {
                "Recipe.Name",
                "Recipe.Description",
                "Recipe.Meal",
                "Recipe.Cuisine",
                "Recipe.PrepTime",
                "Recipe.CookTime",
                "Recipe.Serves",
                "Recipe.ImageFile",
            };

            if (AnyInvalid(fieldsToValidate))
            {
                return(View(vm));
            }

            // Apply values from this view to the one in the cart
            recipeInProgress.Name        = vm.Recipe.Name;
            recipeInProgress.Description = vm.Recipe.Description;
            recipeInProgress.Meal        = vm.Recipe.Meal;
            recipeInProgress.Cuisine     = vm.Recipe.Cuisine;
            recipeInProgress.PrepTime    = vm.Recipe.PrepTime;
            recipeInProgress.CookTime    = vm.Recipe.CookTime;
            recipeInProgress.Serves      = vm.Recipe.Serves;
            recipeInProgress.ImageFile   = vm.Recipe.ImageFile;

            // TODO: Get the user id and put it here
            recipeInProgress.CreatedById = 1;

            // Save the work-in-progress into Session
            SaveRecipeInProgress(recipeInProgress);

            vm.Recipe = recipeInProgress;
            // Go to the next view
            return(RedirectToAction("Add2"));
        }
Ejemplo n.º 22
0
        public RecipeVM Get(int id)
        {
            var model = new RecipeVM();

            Entities.Recipe recipeFromService = _recipesService.GetRecipeById(id);
            _mapper.Map(recipeFromService, model);
            // get image from azure
            if (model.ImageUrl != null)
            {
                //var base64 = _recipesService.GetBase64RecipeImage(model.ImageUrl);
                //model.ImageFile = base64;
                var url = _recipesService.GetUri(model.ImageUrl);
                model.ImageFile = url;
            }
            model.Ingredients.OrderBy(i => i.PositionNo).ToList();
            model.MethodItems.OrderBy(i => i.StepNo).ToList();
            return(model);
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> New(RecipeVM recipeVM)
        {
            try
            {
                Recipe recipeEntity = _recipeMapper.ToModel(recipeVM);
                await _recipeService.Add(recipeEntity);

                if (recipeEntity.Id != Guid.Empty)
                {
                    return(RedirectToAction("List"));
                }
                return(View(recipeVM));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 24
0
        public IActionResult Add2(RecipeVM vm)
        {
            // Get the current values from Session
            Recipe recipeInProgress = GetRecipeInProgress();

            // Since this view does not modify the Recipe object, we'll overwrite with the data from session
            vm.Recipe = recipeInProgress;

            // Validate the fields that are on this form.  If they're no good, no sense in continuing
            string[] fieldsToValidate =
            {
                "NewIngredient.Name",
                "NewIngredient.Unit",
                "NewIngredient.Quantity",
            };
            if (AnyInvalid(fieldsToValidate))
            {
                // If there are validation errors (in the ingrdients), re-show the view so the user sees the errors.
                CreateSelectLists(vm);
                return(View(vm));
            }

            // Add the ingredients from this view to the one in the cart
            recipeInProgress.Ingredients.Add(vm.NewIngredient);

            // Store the work-in-progress to Session
            SaveRecipeInProgress(recipeInProgress);

            // Clear the ingredient field
            vm.NewIngredient = null;

            // Stay on this view to get another ingredient
            vm = new RecipeVM()
            {
                Recipe = recipeInProgress
            };
            CreateSelectLists(vm);
            ModelState.Clear();
            return(View(vm));
        }
Ejemplo n.º 25
0
 public IActionResult Post([FromBody] RecipeVM recipe)
 {
     try
     {
         var response = 0;
         if (recipe.RecipeId > 0)
         {
             response = _adminRecipeService.EditRecipe(recipe);
         }
         else
         {
             //use service to create new recipe and add to db.
             response = _adminRecipeService.CreateNewRecipe(recipe);
         }
         return(Ok(response));
     }
     catch (Exception ex)
     {
         // return error message if there was an exception
         return(BadRequest(new { message = ex.Message }));
     }
 }
Ejemplo n.º 26
0
        public async Task <IActionResult> GetRecipe(int id)
        {
            Recipe recipe = _appDb.Recipes.Find(id);


            var sender = await _userManager.FindByIdAsync(recipe.UserId);

            RecipeVM recipeVM = new RecipeVM();

            recipeVM.RecipeId           = recipe.RecipeId;
            recipeVM.RecipeName         = recipe.RecipeName;
            recipeVM.RecipeCategory     = recipe.RecipeCategory;
            recipeVM.RecipePortions     = recipe.RecipePortions;
            recipeVM.RecipeTime         = recipe.RecipeTime;
            recipeVM.RecipeInstructions = recipe.RecipeInstructions;
            recipeVM.Ingridients        = _appDb.Ingridients.Where(r => id == r.RecipeId).ToList();
            recipeVM.Rating             = _ratingServices.GetRecipeRating(recipe.RecipeId);
            recipeVM.Sender             = sender;
            recipeVM.PostedOn           = recipe.PostedOn;
            recipeVM.Images             = _appDb.Images.Where(i => i.RecipeId == recipe.RecipeId && i.UserId == recipe.UserId).ToList();
            recipeVM.Comments           = _appDb.Comments.Where(c => c.RecipeId == id).ToList();

            foreach (var comment in recipeVM.Comments)
            {
                comment.Likes    = _appDb.CommentLikes.Where(c => c.CommentId == comment.CommentID && c.isLike == true).ToList().Count;
                comment.Dislikes = _appDb.CommentLikes.Where(c => c.CommentId == comment.CommentID && c.isDislike == true).ToList().Count;
                if (_appDb.CommentLikes.Where(c => c.CommentId == comment.CommentID && c.isLike == true && c.UserId == _userManager.GetUserId(User)).Any() == true)
                {
                    comment.Reacted = "like-pressed";
                }
                if (_appDb.CommentLikes.Where(c => c.CommentId == comment.CommentID && c.isDislike == true && c.UserId == _userManager.GetUserId(User)).Any() == true)
                {
                    comment.Reacted = "dislike-pressed";
                }
            }

            return(View("RecipePage", recipeVM));
        }
Ejemplo n.º 27
0
        public ActionResult <RecipeVM> GetRecipe(int id)
        {
            var recipe = _context.Recipe.Find(id);

            if (recipe == null)
            {
                return(NotFound());
            }

            RecipeVM recipeVM = new RecipeVM();

            recipeVM.recipeId    = recipe.RecipeId;
            recipeVM.recipeTitle = recipe.RecipeTitle;
            recipeVM.levelID     = recipe.LevelId;
            recipeVM.image1      = recipe.Image1;
            recipeVM.image2      = recipe.Image2;
            recipeVM.image3      = recipe.Image3;


            List <Steps> steps = _context.Steps.Where(s => s.RecipeId == recipe.RecipeId).Select(s => new Steps
            {
                stepsId  = s.stepsId,
                stepName = s.stepName
            }).ToList();

            recipeVM.steps = steps;

            List <Ingredients> Ingredients = _context.Ingredients.Where(i => i.RecipeId == recipe.RecipeId).Select(s => new Ingredients
            {
                IngredientId   = s.IngredientId,
                IngredientName = s.IngredientName
            }).ToList();

            recipeVM.ingredients = Ingredients;

            return(recipeVM);
        }
        public IActionResult RecipesByEvents(int id)
        {
            List <Recipe>     _recepies    = new List <Recipe>();
            List <RecipeType> _recipeTypes = new List <RecipeType>();

            RecipeVM vm = new RecipeVM();

            if (id <= 0)
            {
                using (ApplicationDbContext ctx = new ApplicationDbContext())
                {
                    _recepies = ctx.Recipe
                                .ToList();
                    _recipeTypes = ctx.RecipeType
                                   .ToList();
                }
            }
            else
            {
                using (ApplicationDbContext ctx1 = new ApplicationDbContext())
                {
                    _recepies = ctx1.Recipe
                                .Where(e => e.EventDetails
                                       .Any(r => r.EventId == id))
                                .ToList();
                    _recipeTypes = ctx1.RecipeType
                                   .ToList();
                }
            }

            vm.recipes     = _recepies;
            vm.recipeTypes = _recipeTypes;


            return(View("~/Views/Recipe/Recipes.cshtml", vm));
        }
Ejemplo n.º 29
0
 // Set all the SelectLists from the DAO, into the given ViewModel
 private void CreateSelectLists(RecipeVM vm)
 {
     vm.Cuisines  = new SelectList(recipeDAO.GetCuisines());
     vm.MealTypes = new SelectList(recipeDAO.GetMealTypes());
     vm.Units     = new SelectList(recipeDAO.GetUnits());
 }
Ejemplo n.º 30
0
 public RecipeView(RecipeVM viewModel)
 {
     InitializeComponent();
     this.DataContext = viewModel;
 }