Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> Update([FromBody] CarModelDto carModelDto)
        {
            try
            {
                await _carModelService.UpdateAsync(carModelDto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }