public async Task <IActionResult> Update(int id, [FromBody] UpdateRegionDto updateRegionDto)
        {
            updateRegionDto.Id = id;
            var result = await _unitOfWork.RegionService.Update(updateRegionDto);

            if (!result.Success)
            {
                return(result.ApiResult);
            }
            return(NoContent());
        }
Ejemplo n.º 2
0
 public IActionResult Update(UpdateRegionDto updateRegionDto)
 {
     try
     {
         var region = _regionService.Update(updateRegionDto);
         return(Ok(region));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 3
0
        public GetRegionDto Update(UpdateRegionDto region)
        {
            var regionInDb = _unitOfWork.RegionRepository.Get(region.Id);

            if (regionInDb == null)
            {
                throw new Exception("Not Found");
            }
            regionInDb.Name = region.Name;
            _unitOfWork.RegionRepository.Update(regionInDb);
            _unitOfWork.SaveChanges();
            return(_mapper.Map <GetRegionDto>(regionInDb));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateRegion([FromBody] UpdateRegionDto updateRegion)
        {
            try
            {
                var result = await _regionCashedService.Update(updateRegion);

                if (result.Errors.Any())
                {
                    return(Conflict());
                }
                RemoveRelatedCash();
                return(Ok());
            }
            catch (Exception ex)
            {
                _logging.WriteExption(ex);
                return(BadRequest());
            }
        }
Ejemplo n.º 5
0
        public async Task <Result> Update(UpdateRegionDto updateRegionDto)
        {
            var region = await FirstOrDefaultAsync(c => c.Id == updateRegionDto.Id);

            if (region.CityId != updateRegionDto.CityId)
            {
                var city = await Context.Cities.FirstOrDefaultAsync(u => u.Id == updateRegionDto.CityId);

                if (city == null)
                {
                    return(Result.Failed(new BadRequestObjectResult(new ApiMessage
                    {
                        Message = ResponseMessage.InvalidCityId
                    })));
                }

                region.City = city;
            }

            _mapper.Map(updateRegionDto, region);
            await Context.SaveChangesAsync();

            return(Result.SuccessFull());
        }