// GET: Ingredients/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // IngredientViewModel ingredient = GetRecipesAndIngredients(id).FirstOrDefault(); IngredientViewModel ingredVM = GetIngredientAndRecipe(id); if (ingredVM == null) { return(HttpNotFound()); } return(View(ingredVM)); }
public async Task <IActionResult> Create(IngredientViewModel ingredientViewModel) { if (ModelState.IsValid) { var ingredientDto = this.ingredientViewModelMapper.MapFrom(ingredientViewModel); await this.ingredientService.CreateIngredientAsync(ingredientDto); this.toastNotification.AddSuccessToastMessage("Ingredient successfully created"); return(RedirectToAction(nameof(Index))); } ModelState.AddModelError(string.Empty, ExceptionMessages.ModelError); this.toastNotification.AddWarningToastMessage("Ingredient couldn't be added"); return(RedirectToAction(nameof(Index))); }
// GET: MealPlan/Create public ActionResult Create() { MealPlanViewModel mealPlanDisplay = new MealPlanViewModel(); mealPlanDisplay.Preparations = new List <PreparationViewModel>(); mealPlanDisplay.Preparations.Add(new PreparationViewModel()); MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository(); mealPlanDisplay.MealPlanAssignedCategories = mealPlanAssignedCategoryRepository.GetDisplayList(0); MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository(); mealPlanDisplay.MealPlanAssignedDietPlans = mealPlanAssignedDietPlanRepository.GetDisplayList(0); NutrientViewModel nutrientViewModel = new NutrientViewModel(); mealPlanDisplay.NutrientDropDownList = nutrientViewModel.GetDropDownList(); MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository(); mealPlanDisplay.MealPlanAssignedNutrients = mealPlanAssignedNutrientRepository.GetDisplayList(0); mealPlanDisplay.MealPlanAssignedNutrients.Add(new MealPlanAssignedNutrientViewModel()); MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository(); mealPlanDisplay.MealPlanAssignedDishes = mealPlanAssignedDishRepository.GetDisplayList(0); mealPlanDisplay.MealPlanAssignedDishes.Add(new MealPlanAssignedDishViewModel()); MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository(); mealPlanDisplay.MealPlanAssignedIngredients = mealPlanAssignedIngredientRepository.GetDisplayList(0); mealPlanDisplay.MealPlanAssignedIngredients.Add(new MealPlanAssignedIngredientViewModel()); UomViewModel uomViewModel = new UomViewModel(); mealPlanDisplay.UomDropDownList = uomViewModel.GetDropDownList(); DishViewModel dishViewModel = new DishViewModel(); mealPlanDisplay.DishDropDownList = dishViewModel.GetDropDownList(); IngredientViewModel ingredientViewModel = new IngredientViewModel(); mealPlanDisplay.IngredientDropDownList = ingredientViewModel.GetDropDownList(); return(View(mealPlanDisplay)); }
public async Task <IActionResult> EditIngredient(IngredientViewModel model) { if (ModelState.IsValid) { var recipeIngredient = await _converterHelper.ToIngredientAsync(model, false); _context.RecipeIngredients.Update(recipeIngredient); await _context.SaveChangesAsync(); return(RedirectToAction($"Details/{model.Id}")); } model.Ingredients = _combosHelper.GetComboIngredients(); return(View(model)); }
public async Task <IActionResult> AddIngredient(IngredientViewModel ingredient) { byte prime; if (ingredient.Primary == "one") { prime = 1; } else { prime = 0; } await ingredientService.CreateIngredientAsync(ingredient.Name, prime); return(RedirectToAction("ManageIngredients")); }
private IngredientViewModel GenerateIngredientViewModel(int typeId, NutrientsPerMeal npm, double userCalories) { var ing = repo.GetRandomIngredient(typeId); var units = repo.GetUnitsOfMesurement(ing.Id); var ingViewModel = new IngredientViewModel(); ingViewModel.BindIngredient(ing); ingViewModel.BaseUnitEnergy = units; var calorieForType = npm.GetCalorieForType(ingViewModel.Type, userCalories); ingViewModel.FillCalculatedEnergyList(calorieForType); return(ingViewModel); }
public IActionResult AddIngredient([FromBody] IngredientViewModel ingredientViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _ingredientService.Insert(ingredientViewModel); if (result.IsError) { return(BadRequest(result)); } return(Ok(result)); }
private void addToRecipeButton_Click(object sender, EventArgs e) { try { if (listOfIngredientsDataGridView.SelectedRows.Count < 1) { throw new SelectionExemption("You must select an ingredient to add to the recipe."); } IngredientViewModel selectedIngredient = (IngredientViewModel)listOfIngredientsDataGridView.SelectedRows[0].DataBoundItem; Navigation.NavigateTo(new AddIngedient(selectedIngredient.GetIngredient()), this); } catch (SelectionExemption error) { MessageBox.Show(error.Message, "Instructions", MessageBoxButtons.OK); } }
private List <IngredientViewModel> GetCheckBoxData() { var model = new List <IngredientViewModel>(); var prod = _context.Produkts.ToList(); foreach (var item in prod) { var ingredientViewModel = new IngredientViewModel(item.ProduktId, item.ProduktNamn); ingredientViewModel.IsSelected = false; model.Add(ingredientViewModel); } return(model); }
public ActionResult UpdateIngredient(int ingredientId, [FromBody] IngredientViewModel ingredientViewModel) { var ingredient = _ingredientService.GetIngredientById(ingredientId); if (ingredient == null) { return(BadRequest("Invalid id.")); } ingredient.Name = ingredientViewModel.Name; ingredient.Description = ingredientViewModel.Description; _ingredientService.UpdateIngredient(ingredient); return(StatusCode(204)); }
public ActionResult Edit(int?Id) { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userId = User.Identity.GetUserId(); var recipe = _unitOfWork.Recipes.GetRecipe(Id, userId); if (recipe == null) { return(new HttpNotFoundResult("Recipe not found")); } var viewModel = new RecipeFormViewModel { Id = recipe.Id, Title = recipe.Title, ContextFoodTypes = _unitOfWork.FoodTypes.GetFoodTypes(), ContextFoods = _unitOfWork.Foods.GetFoods().ToList(), ContextIngredientTypes = _unitOfWork.IngredientTypes.GetIngredientTypes(), ContextIngredients = _unitOfWork.Ingredients.GetIngredients(), ContextUnitOfMeasures = _unitOfWork.UnitOfMeasures.GetUnitOfMeasures(), FoodTypeId = recipe.FoodTypeId, FoodId = recipe.FoodId, FoodName = recipe.Food.FoodName, Heading = "Edit Recipe", ObjectState = ObjectState.Unchanged }; foreach (var ing in recipe.RecipeIngredients) { var ingVM = new IngredientViewModel { Id = ing.Id, RecipeId = ing.RecipeId, Amount = ing.Amount, IngredientId = ing.IngredientId, IngredientTypeId = ing.IngredientTypeId, UnitOfMeasureId = ing.UnitOfMeasureId, ObjectState = ObjectState.Unchanged }; viewModel.RecipeIngredients.Add(ingVM); } return(View("Recipe", viewModel)); }
public MenuViewModel GetMenu(DateTime date, int userId) { ds = SqlHelper.ExecuteDataset(cs, "getMealsForMenu", userId, date); MenuViewModel menu = new MenuViewModel(); menu.ForDay = date; foreach (DataRow row in ds.Tables[0].Rows) { Meal meal = new Meal(); meal.Id = (int)row["IDMeal"]; meal.Name = row["Name"].ToString(); meal.MealNameId = (int)row["MealNameID"]; DataSet ings = SqlHelper.ExecuteDataset(cs, "getIngredientsForMeal", meal.Id); foreach (DataRow ingRow in ings.Tables[0].Rows) { IngredientViewModel ingVM = new IngredientViewModel(); var tmpIng = new Ingredient { Id = (int)ingRow["IDIngredient"], Name = ingRow["Name"].ToString(), TypeId = (int)ingRow["IDIngredientType"], }; ingVM.BindIngredient(tmpIng); DataSet units = SqlHelper.ExecuteDataset(cs, "getCalculatedEnergy", ingVM.Id, meal.Id); foreach (DataRow unit in units.Tables[0].Rows) { UnitEnergy ue = new UnitEnergy(); ue.Value = float.Parse(unit["CalculatedValue"].ToString()); ue.Unit = new UnitOfMesurement { Id = (int)unit["UnitOfMesurementID"], Type = unit["Type"].ToString() }; ingVM.CalculatedUnitEnergy.Add(ue); } meal.Ingredients.Add(ingVM); } menu.Meals.Add(meal); } return(menu); }
public async Task <IActionResult> ListIngredients(int?currentPage, string searchCriteria) { ViewData["SearchParm"] = searchCriteria; var ingredients = await this.ingredientServices.GetIndexPageIngredients(currentPage ?? 1, searchCriteria); var ingViewModels = ingredients.GetViewModels(); var paged = new IngredientViewModel() { currentPage = currentPage ?? 1, items = ingViewModels, TotalPages = this.ingredientServices.GetCount(10) }; return(View(paged)); }
public ActionResult AddIngredient(IngredientViewModel ingredientViewModel) { if (ingredientViewModel == null) { return(BadRequest("Ingredient cannot be null.")); } var ingredient = new Ingredient { Name = ingredientViewModel.Name, Description = ingredientViewModel.Description }; _ingredientService.AddIngredient(ingredient); return(StatusCode(201)); }
public bool EditIngredient(int id, IngredientViewModel ingredientModel) { var ingredient = _context.Ingredients.Where(i => i.Id == id).FirstOrDefault(); if (ingredient != null) { ingredient.Name = ingredientModel.Name; ingredient.StockQuantity = ingredientModel.Quantity; _context.Ingredients.Update(ingredient); _context.SaveChanges(); return(true); } return(false); }
public IngredientDTO MapToDTOFromVM(IngredientViewModel ingredientVM) { if (ingredientVM == null) { return(null); } var ingredientDTO = new IngredientDTO { Name = ingredientVM.Name, }; if (ingredientVM.File != null) { ingredientDTO.ImageData = ingredientVM.ImageData; } return(ingredientDTO); }
public async Task <IActionResult> Edit(int id, IngredientViewModel ingridient) { if (id != ingridient.Id) { return(NotFound()); } if (ingridient.Name == null) { return(NotFound()); } var model = this._ingredientVmMapper.MapDTO(ingridient); await this._ingredientService.EditIngredientAsync(id, model.Name); return(RedirectToAction("List", "Ingredients", new { area = "admin" })); }
public IActionResult Index(string sortOrder, string ingredientType, string searchString, int pageIndex = 1) { int pageSize = 10; int count; var ingredients = ingredientService.GetIngredients(sortOrder, ingredientType, searchString, pageIndex, pageSize, out count); var types = ingredientService.GetTypes(); var indexVM = new IngredientViewModel() { Ingredients = new PaginatedList <IngredientDto>(ingredients, count, pageIndex, pageSize), Types = new SelectList(types), IngredientType = ingredientType, SearchString = searchString, SortOrder = sortOrder }; return(View(indexVM)); }
// GET: Ingredient/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction("Error", "Home")); } var ingredient = await _context.Ingredients.FindAsync(id); if (ingredient == null) { return(RedirectToAction("Error", "Home")); } IngredientViewModel ingredientViewModel = new IngredientViewModel(); ingredientViewModel.Ingredient = ingredient; return(View(ingredientViewModel)); }
public async Task <IActionResult> Create([Bind("Slug,Title,Description")] IngredientViewModel ingredient) { if (ModelState.IsValid) { var result = await _dispatcher.Dispatch(new AddIngredientCommand (ingredient.Title, ingredient.Description, ingredient.Slug)); if (result.IsFailure) { ModelState.AddModelError("", result.Error); return(View(ingredient)); } return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
private void FormIngredient_Load(object sender, EventArgs e) { if (id.HasValue) { try { IngredientViewModel view = service.GetElement(id.Value); if (view != null) { textBoxName.Text = view.IngredientName; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public IActionResult AddIngridient(IngredientViewModel ingridient) { ViewBag.email = Email(); ViewBag.role = Role(); if (ModelState.IsValid) { var ingridientDto = new IngredientDTO { Name = ingridient.Name, DishId = ingridient.DishId }; restaurantService.AddIngridient(ingridientDto); return(RedirectToAction("Index")); } else { return(View(ingridient)); } }
public EntityEntry <Ingredient> CreateIngredient(IngredientViewModel ingredientModel) { Ingredient ingredient = new Ingredient() { Name = ingredientModel.Name, StockQuantity = ingredientModel.Quantity }; var result = _context.Ingredients.Add(ingredient); if (result != null) { _context.SaveChanges(); return(result); } return(null); }
public ActionResult Create(IngredientViewModel ingredient) { if (!this.ModelState.IsValid) { return this.PartialView(ingredient); } var newIngredient = this.ingredients.Create( this.sanitizer.Sanitize(ingredient.Name), this.sanitizer.Sanitize(ingredient.IngredientDetails), this.sanitizer.Sanitize(ingredient.IngredientImage)); var resultIngredient = this.Mapper.Map<IngredientViewModel>(newIngredient); this.TempData["Notification"] = "Ingredient was successfully created!"; return this.PartialView(resultIngredient); }
public void SaveModal() { if (this.Model.Id.HasValue) { var command = DomainServices.Convert <UpdateIngredientCommand>(Model); DomainServices.RunCommand(command); } else { var command = DomainServices.Convert <CreateIngredientCommand>(Model); DomainServices.RunCommand(command); } LoadIngredientsList(); Model = new IngredientViewModel(); ModalService.Hide(); }
public ActionResult Create(IngredientViewModel ingredient) { if (!this.ModelState.IsValid) { return(this.PartialView(ingredient)); } var newIngredient = this.ingredients.Create( this.sanitizer.Sanitize(ingredient.Name), this.sanitizer.Sanitize(ingredient.IngredientDetails), this.sanitizer.Sanitize(ingredient.IngredientImage)); var resultIngredient = this.Mapper.Map <IngredientViewModel>(newIngredient); this.TempData["Notification"] = "Ingredient was successfully created!"; return(this.PartialView(resultIngredient)); }
public async Task <ActionResult> Delete(IngredientViewModel ingredientViewModel) { try { // TODO: Add delete logic here var deletedIngredient = await _ingredientService.DeleteIngredientAsync(ingredientViewModel.Id); if (deletedIngredient != null) { TempData["Message"] = "Ingredient deleted successfully"; return(RedirectToAction(nameof(Index))); } return(View()); } catch { return(View()); } }
public async Task <IActionResult> NewEdit(Guid?id) { var model = new IngredientViewModel(); ViewData["SubTitle"] = "Nuevo"; ViewData["SubTitleDescription"] = "Para crear un nuevo componentes debera llenar el siguiente formulario."; if (id != null && id != Guid.Empty) { var apiService = RestServiceExtension <IIngredientAPI> .For(_enforcerApi.Url, GetUserSession().Token); var resultService = await apiService.GetById(id.Value); model = GetData <IngredientViewModel>(resultService); ViewData["SubTitle"] = "Editar"; ViewData["SubTitleDescription"] = "Para editar el componentes debera llenar el siguiente formulario."; } return(View(model)); }
public RecipeViewModel Map(Recipe r) { RecipeViewModel rvm = new RecipeViewModel(); rvm.IsCompleted = r.IsCompleted; rvm.Name = r.Name; rvm.NumberOfServing = r.NumberOfServing; rvm.PreparationTime = r.PreparationTime; rvm.Year = r.Year; rvm.Direction = r.Direction; rvm.Description = r.Description; rvm.CountryID = r.CountryID; rvm.CategoryID = r.CategoryID; rvm.CaloriesPerServing = r.CaloriesPerServing; rvm.ID = r.ID; Country country = _repositoryContext.Country.FirstOrDefault(e => e.ID == r.CountryID); rvm.CountryID = country.ID; rvm.CountryName = country.Name; Category category = _repositoryContext.Category.FirstOrDefault(e => e.ID == r.CategoryID); rvm.CategoryID = category.ID; rvm.CategoryName = category.Name; rvm.Ingredients = new List <IngredientViewModel>(); foreach (RecipeIngredient item in r.Ingredients) { IngredientViewModel temp = new IngredientViewModel() { IngredientID = item.IngredientID, IngredientName = item.Ingredient.Name, Quantity = item.Quantity, UnitID = item.UnitID, UnitName = item.Unit.Name }; rvm.Ingredients.Add(temp); } return(rvm); }
public ActionResult Create(IngredientViewModel collection) { try { var ingredient = new Ingredient(collection.Name) { Id = collection.Id, }; Repo.Add(ingredient); return(RedirectToAction(nameof(Index))); } catch (Exception e) { _logger.LogTrace(e, "Create ingredient error."); return(View(collection)); } }
public async Task <IActionResult> Edit(IngredientViewModel ingredientVM) { if (ModelState.IsValid) { try { var name = await _ingredientServices.EditIngredienAsync(ingredientVM.MapToDto()); _toast.AddErrorToastMessage($"Ingredient {name} was updated!"); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } } return(RedirectToAction(nameof(Index))); }