public IActionResult Create() { var createModel = new CreateSupplyViewModel { ProductTitles = new SelectList(_productService.GetTitles(), "Id", "Title") }; return(View(createModel)); }
// GET: Meals/Create public ActionResult Create() { List <int> chosenIngredientsIndexes = DataHolder.Supplies.Select(s => s.Ingredient.Id).ToList(); var createSypplyViewModel = new CreateSupplyViewModel { AvailableIngredients = DataHolder.Ingredients.Where(i => !chosenIngredientsIndexes.Contains(i.Id)).ToList() }; return(View(createSypplyViewModel)); }
public IActionResult Create(CreateSupplyViewModel createVM) { if (ModelState.IsValid) { var supplyDTO = _mapper.Map <SupplyBindingModel, SupplyDTO>(createVM.Supply); _supplyService.Add(supplyDTO); return(RedirectToAction(nameof(Items))); } createVM.ProductTitles = new SelectList(_productService.GetTitles(), "Id", "Title"); return(View(createVM)); }
public ActionResult Create(CreateSupplyViewModel createSupplyViewModel) { if (ModelState.IsValid) { Ingredient ingredient = DataHolder.Ingredients.First(i => i.Id == createSupplyViewModel.chosenIngredient); Supply supply = new Supply(ingredient, createSupplyViewModel.Quantity, createSupplyViewModel.DateOfExpiration); DataHolder.Supplies.Add(supply); return(RedirectToAction("Index")); } List <int> chosenIngredientsIndexes = DataHolder.Supplies.Select(s => s.Ingredient.Id).ToList(); createSupplyViewModel.AvailableIngredients = DataHolder.Ingredients.Where(i => !chosenIngredientsIndexes.Contains(i.Id)).ToList(); return(View(createSupplyViewModel)); }
public CreateSupplyWindow(SupplyRepository supplyRepository, SupplyUC owner) : this() { Owner = owner; var vm = new CreateSupplyViewModel(supplyRepository, this); }