public async Task <IActionResult> UpdateAddress(JObject updatedUser) { var user = updatedUser["updatedUser"]; string province = user["provinceId"].ToString(); string district = user["districtId"].ToString(); string ward = user["wardId"].ToString(); string address = user["address"].ToString(); if (province == "0" || ward == "0" || district == "0" || address == "") { return(BadRequest("Vui lòng nhập đầy đủ thông tin")); } string name = user["name"].ToString(); string phone = user["phone"].ToString(); string id = user["id"].ToString(); var tempUser = await _userService.GetAsync(id); await _userService.UpdateAddressAsync(id, name, phone, province, district, ward, address); ///Return updated user to update state in react var returnedUser = (await _userService.GetAsync(id)).Adapt <UserViewModel>(); var provinces = await _provinceService.GetAllAsync(); var wards = await _wardService.GetByDistrictIdAsync(returnedUser.DistrictId); var districts = await _districtService.GetByProvinceIdAsync(returnedUser.ProvinceId); if (returnedUser.ProvinceId != null) { returnedUser.ProvinceName = provinces.Where(x => x.Id == returnedUser.ProvinceId).FirstOrDefault().Name; returnedUser.DistrictName = districts.Where(x => x.Id == returnedUser.DistrictId).FirstOrDefault().Name; returnedUser.WardName = wards.Where(x => x.Id == returnedUser.WardId).FirstOrDefault().Name; } returnedUser.ImgUrl = returnedUser.ImgUrl; returnedUser.BirthDay = Convert.ToDateTime(returnedUser.BirthDay).ToLocalTime().ToString("yyyy-MM-dd"); return(Ok(returnedUser)); }
public async Task <List <Ward> > Get(string id) { return(await _wardService.GetByDistrictIdAsync(id)); }