public async Task <IActionResult> Edit(int id, SellerFormViewModelcs sellerForm) { if (!ModelState.IsValid) { var departaments = await _departamentService.FindAllAsync(); var viewModel = new SellerFormViewModelcs { Departaments = departaments }; return(View(viewModel)); } if (id != sellerForm.Seller.Id) { return(RedirectToAction(nameof(Error), new { message = "In mismatach" })); } try { await _sellerService.UpdateAsync(sellerForm.Seller); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create() { var departaments = await _departamentService.FindAllAsync(); var viewModel = new SellerFormViewModelcs { Departaments = departaments }; return(View(viewModel)); }
public async Task <IActionResult> Create(SellerFormViewModelcs sellers) { if (!ModelState.IsValid) { var departaments = await _departamentService.FindAllAsync(); var viewModel = new SellerFormViewModelcs { Departaments = departaments }; return(View(viewModel)); } await _sellerService.InsertAsync(sellers.Seller); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "In not provided" })); } var obj = await _sellerService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "In not found" })); } var departament = await _departamentService.FindAllAsync(); var viewModel = new SellerFormViewModelcs { Seller = obj, Departaments = departament }; return(View(viewModel)); }