public async Task <IActionResult> Edit(int id, Seller seller) { if (!ModelState.IsValid) { var departments = await _depertmentService.FindAllAsync(); var viewModel = new SellerFromViewModel { Seller = seller, Departments = departments }; return(View(viewModel)); } if (id != seller.Id) { return(RedirectToAction(nameof(Error), (new { message = "Ids não correspondem." }))); } try { await _sellerService.UpdateAsync(seller); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), (new { message = e.Message }))); } }
public IActionResult Create() { var departments = _departmentService.FindAll(); var viewModel = new SellerFromViewModel { Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Create() { var departments = await _depertmentService.FindAllAsync(); var viewModel = new SellerFromViewModel { Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Create(Seller seller) { if (!ModelState.IsValid) { var departments = await _depertmentService.FindAllAsync(); var viewModel = new SellerFromViewModel { Seller = seller, Departments = departments }; return(View(viewModel)); } await _sellerService.InsertAsync(seller); return(RedirectToAction(nameof(Index))); }
public IActionResult Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id not provided" })); } var obj = _sellerService.FindById(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Id not found" })); } List <Department> departments = _departmentService.FindAll(); SellerFromViewModel viewModel = new SellerFromViewModel { Seller = obj, Departments = departments }; return(View(viewModel)); }
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(); SellerFromViewModel viewModel = new SellerFromViewModel { Seller = obj, Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), (new { message = "Id não informado." }))); } var seller = await _sellerService.FindByIdAsync(id.Value); if (seller == null) { return(RedirectToAction(nameof(Error), (new { message = "Id não encontrado." }))); } List <Department> departments = await _depertmentService.FindAllAsync(); SellerFromViewModel viewModel = new SellerFromViewModel { Seller = seller, Departments = departments }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id not Id" })); } 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(); SellerFromViewModel viewModel = new SellerFromViewModel { Seller = obj, Departments = departments }; return(View(viewModel)); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var obj = _sellerService.FindById(id.Value); if (obj == null) { return(NotFound()); } var departments = _departmentService.FindAll(); var sellerViewModel = new SellerFromViewModel() { Departments = departments, Seller = obj }; return(View(sellerViewModel)); }