public async Task <IActionResult> Edit(int id, Seller seller) { if (!ModelState.IsValid) { var departments = await _departmentService.FindAllAsync(); var viewModel = new SellerFormViewModels { Seller = seller, Departments = departments }; return(View(viewModel)); } if (id != seller.Id) { return(RedirectToAction(nameof(Error), new { message = "Id not mismatch." }));; } try { await _sellerService.UpdateAsync(seller); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Edit(int?id) { if (id == null) { //return NotFound(); return(RedirectToAction(nameof(Error), new { message = "Id not found" })); } var obj = await _sellerService.FindByIdAsync(id.Value); if (obj == null) { //return NotFound(); return(RedirectToAction(nameof(Error), new { message = "Id not found" })); } // abre a tela de edicao List <Department> departments = await _departmentService.FindAllAsync(); SellerFormViewModels viewModel = new SellerFormViewModels { Seller = obj, Departments = departments }; // passa para a view do MVC return(View(viewModel)); }
public IActionResult Create() { var departments = _departmentService.FindAll(); var viewModel = new SellerFormViewModels { Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Create() { var departments = await _departmentService.FindAllAsync(); var viewModel = new SellerFormViewModels { Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Create(Seller seller) { if (!ModelState.IsValid) { var departments = await _departmentService.FindAllAsync(); var viewModel = new SellerFormViewModels { Seller = seller, Departments = departments }; 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(); SellerFormViewModels viewModels = new SellerFormViewModels { Seller = obj, Departments = departments }; return(View(viewModels)); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var obj = _sellerService.FindById(id.Value); if (obj == null) { return(NotFound()); } List <Department> departments = _departmentService.FindAll(); SellerFormViewModels viewModel = new SellerFormViewModels { Seller = obj, Departments = departments }; return(View(viewModel)); }
[ValidateAntiForgeryToken] // previne ataques CSRF public async Task <IActionResult> Edit(int id, Seller seller) { if (!ModelState.IsValid) { var departments = await _departmentService.FindAllAsync(); var viewModel = new SellerFormViewModels { Seller = seller, Departments = departments }; return(View(viewModel)); //return View(seller); } if (id != seller.Id) { //return BadRequest(); return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } try { await _sellerService.UpdateAsync(seller); return(RedirectToAction(nameof(Index))); } //catch (NotFoundException e) catch (ApplicationException e) { //return NotFound(); return(RedirectToAction(nameof(Error), new { message = e.Message })); } /* * catch (DbConcurrencyException e) * { * //return BadRequest(); * return RedirectToAction(nameof(Error), new { message = e.Message }); * } */ }