public async Task <IActionResult> Edit(CarModelUpdateDTO carModelUpdateDTO) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CarModel carModel = new CarModel { Id = carModelUpdateDTO.Id, Name = carModelUpdateDTO.Name }; var result = await _carModelService.UpdateAsync(carModel); if (result == -1) { return(BadRequest("Error update")); } return(Ok(carModel)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Edit(CarModelUpdateDTO carModelUpdateDTO) { try { if (!ModelState.IsValid) { return(View(carModelUpdateDTO)); } CarModel carModel = new CarModel { Id = carModelUpdateDTO.Id, Name = carModelUpdateDTO.Name }; var result = await _carModelService.UpdateAsync(carModel); if (result == -1) { ModelState.AddModelError("", "Error update"); return(View(carModelUpdateDTO)); } return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error", ex)); } }
public async Task <ActionResult> Update([FromBody] CarModelDto carModelDto) { try { await _carModelService.UpdateAsync(carModelDto); return(Ok()); } catch (Exception e) { return(BadRequest(e)); } }