public async Task <IActionResult> Create([FromBody] CreateCityDto createCityDto) { var result = await _unitOfWork.CityService.Create(createCityDto); if (!result.Success) { return(result.ApiResult); } return(Created(Url.Link("GetCounty", new { result.Data.Id }), _mapper.Map <CityDto>(result.Data))); }
public async Task <IActionResult> UpdateCity(int cityId, [FromBody] CreateCityDto request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } await _cityService.UpdateAsync(cityId, request); return(ApiResponseOk(null)); }
public async Task UpdateAsync(int cityId, CreateCityDto dto) { var city = await _cityRepository.FindByIdAsync(cityId); if (city == null) { throw new ResourceNotFoundException(); } MapToInstance(dto, city); await _cityRepository.UpdateAsync(city); }
public async Task Create(CreateCityDto dto) { //var City = new CityEntity(); var cityDTo = _mapper.Map <CreateCityDto, CityEntity> (dto); //{ // NameAr = dto.NameAr, // NameEn = dto.NameEn, // CountryId = dto.CountyId, //}; await _DB.Cities.AddAsync(cityDTo); _DB.SaveChanges(); }
/* * public PagedResultDto<CityDto> GetAll(PagedResultRequestDto input) * { * var query = _cityRepository.GetAll(); * int total = query.Count(); * var result = query.Skip(input.SkipCount).Take(input.MaxResultCount).ToList<City>(); * return new PagedResultDto<CityDto>(total,new List<CityDto>( * ObjectMapper.Map<List<CityDto>>(result))); * } */ //新建城市 public CityDto Create(CreateCityDto input) { string requestUrl = "https://restapi.amap.com/v3/geocode/geo?address=" + input.CityName + "&key=c6d99b34598e3721a00fb609eb4a4c1b"; CityGeoDto cityGeo = new CityGeoDto(); using (HttpClient client = new HttpClient()) { HttpResponseMessage responseMessage = client.GetAsync(requestUrl).Result; cityGeo = Newtonsoft.Json.JsonConvert.DeserializeObject <CityGeoDto>(responseMessage.Content.ReadAsStringAsync().Result); } if (!cityGeo.geocodes.Any()) { throw new ArgumentException("Error Input"); } GeocodeModel geoModel = cityGeo.geocodes[0]; var location = geoModel.location.Split(","); var entity = new City() { CityName = geoModel.city, CityCode = geoModel.citycode, Longitude = decimal.Parse(location[0]), Latitude = decimal.Parse(location[1]) }; var city = _cityRepository.GetAll().Where(c => c.CityCode == entity.CityCode); if (city.Any() && (city.FirstOrDefault().IsDeleted == true)) { var city_old = city.FirstOrDefault(); city_old.IsDeleted = false; var result_old = _cityRepository.Update(city_old); CurrentUnitOfWork.SaveChanges(); return(result_old.MapTo <CityDto>()); } if (city.Any()) { throw new ApplicationException("城市已存在!"); } var result = _cityRepository.Create(entity); CurrentUnitOfWork.SaveChanges(); return(result.MapTo <CityDto>()); }
public async Task <IActionResult> UpdateCity([FromBody] CreateCityDto newCity) { if (newCity == null) { return(BadRequest("no new city")); } if (!ModelState.IsValid) { return(BadRequest("city object is poorly formatted")); } var cityToAdd = new CityDto(); cityToAdd.Name = newCity.Name; cityToAdd.Desciption = newCity.Description; await _dataStore.AddCity(cityToAdd); return(Ok(cityToAdd)); }
public async Task <Result <CityDto> > Create(CreateCityDto createCityDto) { var county = await Context.Counties.FirstOrDefaultAsync(u => u.Id == createCityDto.CountyId); if (county == null) { return(Result <CityDto> .Failed(new BadRequestObjectResult(new ApiMessage { Message = ResponseMessage.InvalidCountyId }))); } var city = _mapper.Map <City>(createCityDto); city.County = county; await AddAsync(city); await Context.SaveChangesAsync(); return(Result <CityDto> .SuccessFull(_mapper.Map <CityDto>(city))); }
public async Task CreateAsync(CreateCityDto dto) { var city = Map <CreateCityDto, City>(dto); await _cityRepository.CreateAsync(city); }
public async Task <IActionResult> CreateAsync([FromForm] CreateCityDto dto) { await _cityservice.Create(dto); return(Ok(GetRespons())); }