public async Task <IActionResult> Edit(int id, Seller seller) { if (!ModelState.IsValid) { var departament = await _departmentService.FindAllAsync(); var viewModel = new SellerFomViewModel { Seller = seller, Departments = departament }; return(View(viewModel)); } if (id != seller.Id) { return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } try { await _sellerService.UpdateAsync(seller); return(RedirectToAction(nameof(Index))); } catch (NotFoundException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create() { var departments = await _departmentService.FindAllAsync(); var viewModel = new SellerFomViewModel { Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Create(Seller seller) { if (!ModelState.IsValid) { var departament = await _departmentService.FindAllAsync(); var viewModel = new SellerFomViewModel { Seller = seller, Departments = departament }; return(View(viewModel)); } await _sellerService.InsertAsync(seller); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id not provided" })); } var obj = await _sellerService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Id not found" })); } List <Department> departments = await _departmentService.FindAllAsync(); SellerFomViewModel viewModel = new SellerFomViewModel { Seller = obj, Departments = departments }; return(View(viewModel)); }