public IHttpActionResult FavSync(FavModel model) { ApiServerMsg result = new ApiServerMsg(); try { if (XzyWebSocket._dicSockets.ContainsKey(model.uuid)) { var res = XzyWebSocket._dicSockets[model.uuid].weChatThread.Wx_FavSync(model.favkey); result.Success = true; result.Context = res; return(Ok(result)); } else { result.Success = false; result.Context = "不存在该websocket连接"; return(Ok(result)); } } catch (Exception e) { result.Success = false; result.ErrContext = e.Message; return(Ok(result)); } }
private async void favButton_Clicked(object sender, System.EventArgs e) { FavModel tempFav = new FavModel(); tempFav.id = globals.Globals.TheUser._id; tempFav.item_id = item.id; var jsonString = JsonConvert.SerializeObject(tempFav, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); requestString = jsonString; if (!globals.Globals.TheUser.favorites.Contains(item.id)) { globals.Globals.TheUser.favorites.Add(item.id); favButton.Source = "FavImg.png"; using (var httpClient = new HttpClient()) { var httpContent = new StringContent(requestString, Encoding.UTF8, "application/json"); await httpClient.PostAsync("http://52.13.18.254:3000/addfavorite", httpContent); //debugging Console.WriteLine("JSON: " + requestString); Console.WriteLine("POST: " + httpContent.ToString()); } } else { globals.Globals.TheUser.favorites.Remove(item.id); favButton.Source = "noFavImg.png"; using (var httpClient = new HttpClient()) { var httpContent = new StringContent(requestString, Encoding.UTF8, "application/json"); await httpClient.PostAsync("http://52.13.18.254:3000/removefavorite", httpContent); } } }
public ActionResult postfav(FavModel FavMod) { try { var user = userServices.postfav(FavMod); if (user == null) { return(NotFound()); } return(Ok(user)); } catch (Exception ex) { logHelper.ErrorLogs("UsersController", "postfav", "", ex); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public IActionResult FavIlan() { var favoriilanlar = _favService.GetFavByUserId(_userManager.GetUserId(User)); var model = new FavModel() { Favs = favoriilanlar.Select(i => new FavItemModel() { IlanId = i.IlanId, resimUrl = i.Ilan.IlanResimleri[0].url, ilanBasligi = i.Ilan.ilanBasligi, markaAdi = i.Ilan.Marka.adi, seri = i.Ilan.seri, model = i.Ilan.model, fiyat = i.Ilan.fiyat }).ToList() }; return(View(model)); }
public IHttpActionResult FavSync(FavModel model) { ApiServerMsg apiServerMsg = new ApiServerMsg(); try { if (XzyWebSocket._dicSockets.ContainsKey(model.uuid)) { string context = XzyWebSocket._dicSockets[model.uuid].weChatThread.Wx_FavSync(model.favkey); apiServerMsg.Success = true; apiServerMsg.Context = context; return(Ok(apiServerMsg)); } apiServerMsg.Success = false; apiServerMsg.Context = "不存在该websocket连接"; return(Ok(apiServerMsg)); } catch (Exception ex) { apiServerMsg.Success = false; apiServerMsg.ErrContext = ex.Message; return(Ok(apiServerMsg)); } }
//START: BUTTONS EVENTS ####################################################### private async void itemEntry_Tapped(object sender, ItemTappedEventArgs e) { //Creating an object of type ItemModel ItemModel item = (ItemModel)((ListView)sender).SelectedItem; ((ListView)sender).SelectedItem = null; string itemId = item.id; ItemModel tempItem = new ItemModel(); tempItem.id = itemId; //item serialized to be sent as the request to the API //handles parameters not entered by the user, that way they are not included in the json string so the API doesn't have to parse and check for nulls. var jsonString = JsonConvert.SerializeObject(tempItem, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); requestString = jsonString; //Creating the http client which will provide us with the network capabilities using (var httpClient = new HttpClient()) { //request string to be sent to the API var httpContent = new StringContent(requestString, Encoding.UTF8, "application/json"); //sending the previously created request to the api and waiting for a response that will be saved in the httpResponse var // NOTE: if the api's base url changes this has to be modified. var httpResponse = await httpClient.PostAsync("http://52.13.18.254:3000/searchbyid", httpContent); //to visualize the json sent over the network comment the previous line, uncomment the next one and go to the link. //var httpResponse = await httpClient.PostAsync("https://putsreq.com/qmumqAwIq9s5RBEfbNfh", httpContent); //verifying that response is not empty if (httpResponse.Content != null) { //response into a usable var var responseContent = await httpResponse.Content.ReadAsStringAsync(); //debugging Console.WriteLine("JSON: " + requestString); Console.WriteLine("POST: " + httpContent.ToString()); Console.WriteLine("GET: " + responseContent); responseString = responseContent; } } var itemsList = JsonConvert.DeserializeObject <ObservableCollection <ItemModel> >(responseString); var itemReceived = itemsList[0]; FavModel itemViewed = new FavModel(); itemViewed.id = globals.Globals.TheUser._id; itemViewed.item_id = itemId; jsonString = JsonConvert.SerializeObject(itemViewed, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); requestString = jsonString; using (var httpClient = new HttpClient()) { var httpContent = new StringContent(requestString, Encoding.UTF8, "application/json"); var httpResponse = await httpClient.PostAsync("http://52.13.18.254:3000/itemviewed", httpContent); } globals.Globals.TheUser.recently_viewed.Add(itemReceived.id); //calling the ItemPage into the stack and passing the selected item by the user await Navigation.PushAsync(new ItemPage(itemReceived)); }
public FavModel postfav(FavModel favModel) { favModel.id = MongoDB.Bson.ObjectId.GenerateNewId().ToString(); eVChargingDBContext.favmodel.InsertOne(favModel); return(favModel); }