public async Task <IActionResult> UpdateCountry([FromBody] UpdateCountryModel updateCountryModel) { UpdateCountryDto updateCountryDto = _mapper.Map <UpdateCountryDto>(updateCountryModel); await _countryService.UpdateCountryAsync(updateCountryDto); return(Ok()); }
public async Task UpdateCountryAsync(UpdateCountryDto updateCountryDto) { if (updateCountryDto == null) { throw new ArgumentNullException(nameof(updateCountryDto)); } Country countryToBeUpdated = await _unitOfWork.Repository <Country>().GetEntityByIdAsync(updateCountryDto.CountryId); if (countryToBeUpdated != null) { countryToBeUpdated.CountryName = updateCountryDto.CountryName; countryToBeUpdated.IsActive = updateCountryDto.IsActive; _unitOfWork.Repository <Country>().UpdateEntity(countryToBeUpdated); await _unitOfWork.SaveChangesAsync(); } }
public async Task <IActionResult> Update([FromBody] UpdateCountryDto updateCountryDto) { try { var result = await _countryCashedService.Update(updateCountryDto); if (result.Errors.Any()) { return(Conflict()); } RemoveRelatedCash(); return(Ok()); } catch (Exception ex) { _logging.WriteExption(ex); return(BadRequest()); } }
public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDto countryDto) { if (!ModelState.IsValid || id < 1) { _logger.LogError($"Invalid Update Attempt in {nameof(UpdateCountry)}"); return(BadRequest(ModelState)); } var country = await _unitOfWork.Hotels.Get(q => q.Id == id); if (country == null) { _logger.LogError($"Invalid Update Attempt in {nameof(UpdateCountry)}"); return(BadRequest("Submitted Data is invalid"));; } _mapper.Map(countryDto, country); _unitOfWork.Hotels.Update(country); await _unitOfWork.Save(); return(NoContent()); }