public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var snapshot = (QuerySnapshot)value; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; cartresult.Clear(); foreach (DocumentSnapshot item in documents) { Cart product = new Cart(); product.ID = item.Id; product.productname = item.Get("productname").ToString(); product.productimgurl = item.Get("imageurl") != null?item.Get("imageurl").ToString() : ""; product.unitprice = item.GetLong("unitprice").IntValue() != 0 ? item.GetLong("unitprice").IntValue() : 1; //item.Get("amount") != 0 ? item.Get("amount") : 1; //user.ProfileImage = item.Get("profileimage") != null ? item.Get("profileimage").ToString() : ""; cartresult.Add(product); } if (cartadapter != null) { cartadapter.NotifyDataSetChanged(); } } }
public void OnResponse(Java.Lang.Object response) { progressDialog.Show(); try { JSONArray jsonArray = new JSONArray(response.ToString()); if (jsonArray.Length() > 0) { topSellList.Clear(); for (int i = 0; i < jsonArray.Length(); i++) { JSONObject jsonObject1 = jsonArray.GetJSONObject(i); string product_id = jsonObject1.GetString("itemmastid"); string varient_id = jsonObject1.GetString("itemmastid"); string product_name = jsonObject1.GetString("itemid"); string description = jsonObject1.GetString("itemdesc"); string pprice = jsonObject1.GetString("selrate"); string quantity = "50"; string product_image = jsonObject1.GetString("ItemImage"); string mmrp = jsonObject1.GetString("MRP"); string unit = jsonObject1.GetString("priunitvalue"); string count = "0"; string totalOff = string.Empty; if ((decimal.Parse(mmrp)) > 0) { var savePrice = (decimal.Parse(mmrp) - decimal.Parse(pprice)); var per = (savePrice / (decimal.Parse(mmrp)) * 100); totalOff = System.Math.Round(per, 0).ToString(); } int warehouseid = jsonObject1.GetString("WareHouseToId") == "" ? 0 : Convert.ToInt32(jsonObject1.GetString("WareHouseToId")); int rowstate = 0; CartModel recentData = new CartModel(product_id, product_name, description, pprice, "Unit : " + " " + unit, product_image, "%" + totalOff + " " + "Off", mmrp, count, unit, warehouseid, rowstate); recentData.setVarient_id(varient_id); topSellList.Add(recentData); } topSellingAdapter = new CartAdapter(Activity, topSellList); rv_top_selling.SetLayoutManager(new LinearLayoutManager(this.Activity)); rv_top_selling.SetAdapter(topSellingAdapter); topSellingAdapter.NotifyDataSetChanged(); } else { string msg = "No Record found"; Toast.MakeText(Context, msg, ToastLength.Short).Show(); } progressDialog.Dismiss(); } catch (JSONException e) { e.PrintStackTrace(); } progressDialog.Dismiss(); }