public async Task <IActionResult> Update(int id, [FromBody] CityUpdateDTO cityDTO) { try { if (id < 1 || cityDTO == null || id != cityDTO.IDCity) { return(BadRequest()); } var isExists = await _cityRepository.isExists(id); if (!isExists) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = _mapper.Map <City>(cityDTO); var isSuccess = await _cityRepository.Update(city); if (!isSuccess) { return(InternalError($"Update failed.")); } return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
public async Task <CityDTO> PatchAsync(CityUpdateDTO city) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.CityUpdateService.UpdateAsync(this.Mapper.Map <CityUpdateModel>(city)); return(this.Mapper.Map <CityDTO>(result)); }
/// <summary> /// Updae City AppService /// </summary> /// <returns>bool<bool></returns> public async Task <bool> UpdateCity(CityUpdateDTO cityUpdateDTO) { #region Declare a return type with initial value. bool isUpdated = false; #endregion try { if (cityUpdateDTO != null) { isUpdated = await CityBusinessMapping.UpdateCity(cityUpdateDTO); } } catch (Exception exception) {} return(isUpdated); }
public async Task <IActionResult> UpdateCityName(int id, CityUpdateDTO city) { var model = await this.uowService.CityRepository.FindCity(id); if (model == null) { return(BadRequest("Update not allowed.")); } model.LastUpdatedBy = 1; model.LastUpdateOn = DateTime.Now; this.mapper.Map(city, model); await this.uowService.SaveAsync(); return(Ok(city)); }
/// <summary> /// Mapping User Activity Log DTO to Action /// </summary> /// <param name=></param> /// <param name=></param> /// <returns></returns> public City MappingCityupdateDTOToCity(City city, CityUpdateDTO CityUpdateDTO) { #region Declare Return Var with Intial Value City City = city; #endregion try { if (CityUpdateDTO.CityId > default(int)) { City.CityId = CityUpdateDTO.CityId; City.CountyId = CityUpdateDTO.CountyId; City.CityName = CityUpdateDTO.CityName; } } catch (Exception exception) { } return(City); }
/// <summary> /// Update User Action Activity Log /// </summary> /// <param name=></param> /// <returns>bool</returns> public async Task <bool> UpdateCity(CityUpdateDTO CityUpdateDTO) { #region Declare a return type with initial value. bool isCityUpdated = default(bool); #endregion try { if (CityUpdateDTO != null) { #region Vars City City = null; #endregion #region Get Activity By Id City = await UnitOfWork.CityRepository.GetById(CityUpdateDTO.CityId); #endregion if (City != null) { #region Mapping City = CityMapping.MappingCityupdateDTOToCity(City, CityUpdateDTO); #endregion if (City != null) { #region Update Entity UnitOfWork.CityRepository.Update(City); isCityUpdated = await UnitOfWork.Commit() > default(int); #endregion } } } } catch (Exception exception) { } return(isCityUpdated); }
public async Task <ActionResult <CommonAPIResponse <bool> > > UpdateCity(CityUpdateDTO CityUpdateDTO) { #region Declare return type with initial value. JsonResult jsonResult = GetDefaultJsonResult <bool>(); #endregion try { #region Validate userUpdateDTO for nullability before prepaing the response. if (await CityAppService.UpdateCity(CityUpdateDTO)) { 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); }