示例#1
0
        public async Task <IActionResult> Edit(CarOwnerUpdateDTO carOwnerUpdateDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CarOwner carOwner = new CarOwner
                    {
                        Id      = carOwnerUpdateDTO.Id,
                        CarId   = carOwnerUpdateDTO.CarId,
                        OwnerId = carOwnerUpdateDTO.OwnerId
                    };
                    var result = await _carOwnerService.UpdateAsync(carOwner);

                    if (result == -1)
                    {
                        await GetSelected();

                        ModelState.AddModelError("", "Error update");
                        return(View(carOwnerUpdateDTO));
                    }
                    return(RedirectToAction("Index"));
                }
                await GetSelected();

                return(View(carOwnerUpdateDTO));
            }
            catch (Exception ex)
            {
                return(View("Error", ex));
            }
        }
示例#2
0
        public async Task <IActionResult> Edit(CarOwnerUpdateDTO carOwnerUpdateDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                CarOwner carOwner = new CarOwner
                {
                    Id      = carOwnerUpdateDTO.Id,
                    CarId   = carOwnerUpdateDTO.CarId,
                    OwnerId = carOwnerUpdateDTO.OwnerId
                };
                var result = await _carOwnerService.UpdateAsync(carOwner);

                if (result == -1)
                {
                    return(BadRequest("Error update"));
                }
                return(Ok(carOwner));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#3
0
        public async Task <IActionResult> Edit(CarOwner carOwner)
        {
            await GetSelected();

            var model = new CarOwnerUpdateDTO
            {
                Id      = carOwner.Id,
                CarId   = carOwner.CarId,
                OwnerId = carOwner.OwnerId
            };

            return(View(model));
        }