public async Task <IActionResult> Update(int id, [FromBody] CountryUpdateDTO countryDTO) { try { if (id < 1 || countryDTO == null || id != countryDTO.IDCountry) { return(BadRequest()); } var isExists = await _countryRepository.isExists(id); if (!isExists) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var country = _mapper.Map <Country>(countryDTO); var isSuccess = await _countryRepository.Update(country); if (!isSuccess) { return(InternalError($"Update failed.")); } return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
/// <summary> /// Updae Country AppService /// </summary> /// <returns>bool<bool></returns> public async Task <bool> UpdateCountry(CountryUpdateDTO countryUpdateDTO) { #region Declare a return type with initial value. bool isUpdated = false; #endregion try { if (countryUpdateDTO != null) { isUpdated = await CountryBusinessMapping.UpdateCountry(countryUpdateDTO); } } catch (Exception exception) {} return(isUpdated); }
/// <summary> /// Mapping User Activity Log DTO to Action /// </summary> /// <param name=></param> /// <param name=></param> /// <returns></returns> public Country MappingCountryupdateDTOToCountry(Country country, CountryUpdateDTO CountryUpdateDTO) { #region Declare Return Var with Intial Value Country Country = country; #endregion try { if (CountryUpdateDTO.CountryId > default(int)) { Country.CountryId = CountryUpdateDTO.CountryId; Country.CountryName = CountryUpdateDTO.CountryName; } } catch (Exception exception) { } return(Country); }
/// <summary> /// Update User Action Activity Log /// </summary> /// <param name=></param> /// <returns>bool</returns> public async Task <bool> UpdateCountry(CountryUpdateDTO CountryUpdateDTO) { #region Declare a return type with initial value. bool isCountryUpdated = default(bool); #endregion try { if (CountryUpdateDTO != null) { #region Vars Country Country = null; #endregion #region Get Activity By Id Country = await UnitOfWork.CountryRepository.GetById(CountryUpdateDTO.CountryId); #endregion if (Country != null) { #region Mapping Country = CountryMapping.MappingCountryupdateDTOToCountry(Country, CountryUpdateDTO); #endregion if (Country != null) { #region Update Entity UnitOfWork.CountryRepository.Update(Country); isCountryUpdated = await UnitOfWork.Commit() > default(int); #endregion } } } } catch (Exception exception) { } return(isCountryUpdated); }
public async Task <ActionResult <CommonAPIResponse <bool> > > UpdateCountry(CountryUpdateDTO CountryUpdateDTO) { #region Declare return type with initial value. JsonResult jsonResult = GetDefaultJsonResult <bool>(); #endregion try { #region Validate userUpdateDTO for nullability before prepaing the response. if (await CountryAppService.UpdateCountry(CountryUpdateDTO)) { jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.Success, CurrentLanguagId), true, HttpStatusCode.OK); } else { jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.InvalidCredentials, CurrentLanguagId), false, HttpStatusCode.BadRequest); } #endregion } catch (Exception exception) { } return(jsonResult); }
public IActionResult Put([FromBody] CountryUpdateDTO country) { if (country == null) { return(BadRequest(new ErrorViewModel { ErrorCode = "400", ErrorMessage = "Thông tin cung cấp không chính xác" })); } if (!ModelState.IsValid) { var errorViewModel = new ErrorViewModel { ErrorCode = "400", ErrorMessage = ModelState.ToErrorMessages() }; return(BadRequest(errorViewModel)); } var countryToUpdate = this._countryRepository.GetByCode(country.Code); if (countryToUpdate == null) { return(NotFound(new ErrorViewModel { ErrorCode = "404", ErrorMessage = "Quốc gia cần cập nhật không tìm thấy" })); } bool isExisting = this._countryRepository.CheckExistingName( country.Code, country.Name); if (isExisting) { return(BadRequest(new ErrorViewModel { ErrorCode = "400", ErrorMessage = "Tên quốc gia này đã tồn tại." })); } countryToUpdate.Name = country.Name; countryToUpdate.UpdatedBy = "admin"; countryToUpdate.UpdatedDate = DateTime.Now; bool isSuccess = this._countryRepository.Update(countryToUpdate); if (isSuccess == false) { return(StatusCode(500, new ErrorViewModel { ErrorCode = "500", ErrorMessage = "Có lỗi trong quá trình cập nhật dữ liệu." })); } return(Ok(countryToUpdate)); }