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));
            }
        }
Beispiel #2
0
        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 <CarBrandModel> Put(int id, [FromBody] CarBrandModel model)
        {
            var result = await _carBrandService.UpdateAsync(model);

            return(result);
        }