public async Task <IActionResult> Create(CarBrandCreateDTO carBrandCreateDTO) { try { if (ModelState.IsValid) { CarBrand carBrand = new CarBrand { Name = carBrandCreateDTO.Name }; var result = await _carBrandService.CreateAsync(carBrand); if (result == -1) { return(BadRequest("Error create")); } return(Ok(carBrand)); } return(BadRequest(ModelState)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Create(CarBrandCreateDTO carBrandCreateDTO) { try { if (ModelState.IsValid) { CarBrand carBrand = new CarBrand { Name = carBrandCreateDTO.Name }; var result = await _carBrandService.CreateAsync(carBrand); if (result == -1) { ModelState.AddModelError("", "Error create"); return(View(carBrandCreateDTO)); } return(RedirectToAction("Index")); } return(View(carBrandCreateDTO)); } catch (Exception ex) { return(View("Error", ex)); } }