Beispiel #1
0
        public async Task <IActionResult> Create(CarModelCreateDTO carModelCreateDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(carModelCreateDTO));
                }
                CarModel carModel = new CarModel
                {
                    Name = carModelCreateDTO.Name
                };
                var result = await _carModelService.CreateAsync(carModel);

                if (result == -1)
                {
                    ModelState.AddModelError("", "Error create");
                    return(View(carModelCreateDTO));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View("Error", ex));
            }
        }
        public async Task <IActionResult> Create(CarModelCreateDTO carModelCreateDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CarModel carModel = new CarModel
                    {
                        Name = carModelCreateDTO.Name
                    };
                    var result = await _carModelService.CreateAsync(carModel);

                    if (result == -1)
                    {
                        return(BadRequest("Error create"));
                    }
                    return(Ok(carModel));
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }