public async Task <IActionResult> Edit(CarBrandUpdateDTO carBrandUpdateDTO) { try { if (!ModelState.IsValid) { return(View(carBrandUpdateDTO)); } CarBrand carBrand = new CarBrand { Id = carBrandUpdateDTO.Id, Name = carBrandUpdateDTO.Name }; var result = await _carBrandService.UpdateAsync(carBrand); if (result == -1) { ModelState.AddModelError("", "Error update"); return(View(carBrandUpdateDTO)); } return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error", ex)); } }
public async Task <IActionResult> Edit(CarBrandUpdateDTO carBrandUpdateDTO) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CarBrand carBrand = new CarBrand { Id = carBrandUpdateDTO.Id, Name = carBrandUpdateDTO.Name }; var result = await _carBrandService.UpdateAsync(carBrand); if (result == -1) { return(BadRequest("Error update")); } return(Ok(carBrand)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult Edit(CarBrand carBrand) { var model = new CarBrandUpdateDTO { Id = carBrand.Id, Name = carBrand.Name }; return(View(model)); }