コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
            }
        }