/// <summary> /// 修改房源 /// </summary> /// <param name="addHousePara"></param> /// <returns></returns> public static async Task <string> ModifyHouse(AddHousePara addHousePara) { string url = "ModHouseData"; //string httpContent = JsonConvert.SerializeObject(addClientPara); //string httpContent = ""; //Type type = addHousePara.GetType(); //foreach (var item in type.GetProperties()) //{ // httpContent += (item.Name + "=" + item.GetValue(addHousePara, null) + "&"); //} //httpContent = httpContent.TrimEnd('&'); var requestPost = new RestRequest(url, Method.POST); requestPost.AddHeader("content-type", "multipart/form-data"); //requestPost.AddParameter("multipart/form-data", form, ParameterType.RequestBody); Type type = addHousePara.GetType(); foreach (var item in type.GetProperties()) { //httpContent += (item.Name + "=" + item.GetValue(addHousePara, null) + "&"); requestPost.AddParameter(item.Name, item.GetValue(addHousePara, null)); } string content = await RestSharpHelper <string> .PostFormAsyncWithoutDeserialization(requestPost); return(content); }
/// <summary> /// 新增房源 /// </summary> /// <param name="addHousePara"></param> /// <param name="photos"></param> /// <returns></returns> public static async Task <string> AddNewHouse(AddHousePara addHousePara, IList <string> photos) { Console.WriteLine(JsonConvert.SerializeObject(addHousePara)); string url = "NewHouseData"; //string httpContent = JsonConvert.SerializeObject(addClientPara); //string httpContent = ""; //Type type = addHousePara.GetType(); //foreach (var item in type.GetProperties()) //{ // httpContent += (item.Name + "=" + item.GetValue(addHousePara, null) + "&"); //} //httpContent = httpContent.TrimEnd('&'); var requestPost = new RestRequest(url, Method.POST); requestPost.AddHeader("content-type", "multipart/form-data"); //requestPost.AddParameter("multipart/form-data", form, ParameterType.RequestBody); Type type = addHousePara.GetType(); foreach (var item in type.GetProperties()) { //httpContent += (item.Name + "=" + item.GetValue(addHousePara, null) + "&"); requestPost.AddParameter(item.Name, item.GetValue(addHousePara, null) ?? ""); } //如果没有图片就传空值 if (photos == null || photos.Count < 1) { requestPost.AddFile("photos", new byte[0], "1"); } else { foreach (var item in photos) { requestPost.AddFile("photos", item); } } string content = await RestSharpHelper <string> .PostFormAsyncWithoutDeserialization(requestPost); return(content); }
public AddHouseViewModel() { Title = "新增房源"; btnText = "确认新增"; ImageList = new ObservableCollection <string>(); TradeList = new List <string> { "出售", "出租" }; DirectionList = new List <string> { "南北", "东西", "南", "北", "东", "西", "东南", "西南", "东北", "西北" }; DecorationList = new List <string> { "毛坯", "简装", "中装", "精装", "豪装", "其它" }; PropertyTypeList = new List <string> { "多层", "高层", "小高层", "多层复式", "高层复式", "多层跃式", "高层跃式", "独立别墅", "联体别墅", "双拼别墅", "叠加别墅", "围院别墅", "裙楼", "四合院" }; PropertySourceList = new List <string> { "上店", "驻守", "贴单", "网络", "朋友", "同行", "安居客", "58", "房天下", "68好房", "平台推荐" }; PropertyUseTypeList = new List <string> { "住宅", "商住", "商铺", "网点", "写字楼", "厂房", "写厂", "铺厂", "仓库", "地皮", "工厂", "车位", "公寓", "其他" }; PropertyRightList = new List <string> { "单独所有", "共有", "单位产权" }; CredentialsList = new List <string> { "不动产证", "房权证", "购房合同", "委托公证", "法院拍卖", "判决书", "离婚协议", "继承" }; StatusList = new List <string> { "自住", "空房", "出租", "经商", "查封" }; LookWaysList = new List <string> { "预约", "有钥匙", "借钥匙", "直接看" }; CommissionPayList = new List <string> { "满佣", "折扣", "拒付", "商议" }; PaymentList = new List <string> { "一次性", "按揭", "垫资解押", "月付", "季度付", "半年付", "年付商议" }; FurnitureList = new List <string> { "少量", "全配", "无", "可协商" }; OwnershipList = new List <string> { "商品房", "房改房", "经济适用房", "集体房", "军产房", "其它房" }; BuiltYearList = new List <string>(); for (int i = 1970; i <= 2030; i++) { BuiltYearList.Add(i.ToString()); } Para = new AddHousePara(); Estate = new EstateItemInfo(); //BedroomList = new List<string>(); //DiningroomList = new List<string>(); //BathroomList = new List<string>(); //BalconyList = new List<string>(); //for (int i = 0; i < 10; i++) //{ // BedroomList.Add() //} AddImageCommand = new Command(async() => { await GetReadPermissionAsync(); List <string> list = await DependencyService.Get <IImagePickerService>().PickImageAsync(); list?.ForEach(item => ImageList.Add(item)); //if (list != null) //{ //foreach (var item in streams) //{ //stack.Children.Add(new Image() { Source = ImageSource.FromStream(() => item) }); //stack.Children.Add(new Image() { Source = item }); //} //image.Source = ImageSource.FromStream(() => stream); //byte[] bytes = new byte[stream.Length]; //stream.Read(bytes, 0, bytes.Length); //stream.Seek(0, SeekOrigin.Begin); // //string base64 = Convert.ToBase64String(bytes); //Console.WriteLine(base64); //} }, () => { return(true); }); DoubleTappedCommand = new Command <string>(async(index) => { bool result = await Application.Current.MainPage.DisplayAlert("删除", "要删除这张照片吗?", "确定", "取消"); if (result) { ImageList.Remove(index); } }, (index) => { return(true); }); AddCommand = new Command(() => { if (CheckInput()) { AddNewHouse(); } }, () => { return(true); }); ClearCommand = new Command(() => { }, () => { return(true); }); ToEstateSelectCommand = new Command(async() => { EstateSelectPage estateSelectPage = new EstateSelectPage(); await Application.Current.MainPage.Navigation.PushAsync(estateSelectPage); }, () => { return(true); }); GetUnitsCommand = new Command <int>((index) => { GetUnits(RawBuildingList[index].BuildingID); }, (index) => { return(true); }); }