public async Task <IActionResult> Edit(int id, ItemOfProduct itemOfProduct) { if (id != itemOfProduct.Id) { ViewBag.ErrorMessage = "لايوجد بيانات"; return(View("NotFound")); } if (ModelState.IsValid) { try { _repository.Update <ItemOfProduct>(itemOfProduct); await _repository.SavaAll(); } catch (DbUpdateConcurrencyException) { if (_repository.GetItemOfProduct(itemOfProduct.Id) == null) { ViewBag.ErrorMessage = "لايوجد بيانات"; return(View("NotFound")); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TypeOfProductId"] = new SelectList(await _repository.GetTypeOfProducts(), "Id", "Name", itemOfProduct.Id); return(View(itemOfProduct)); }
public async Task <IActionResult> Create(ItemOfProduct itemOfProduct) { if (ModelState.IsValid) { _repository.Add <ItemOfProduct>(itemOfProduct); await _repository.SavaAll(); return(RedirectToAction(nameof(Index))); } ViewData["TypeOfProductId"] = new SelectList(await _repository.GetTypeOfProducts(), "Id", "Name", itemOfProduct.Id); return(View(itemOfProduct)); }