public async Task <string> Additem(mCartS item) { try { var Itemcreds = Newtonsoft.Json.JsonConvert.SerializeObject(item); HttpContent ItemContent = new StringContent(Itemcreds, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { HttpResponseMessage response = await client.PostAsync(Keys.Url_Main + "cart/add", ItemContent); using (HttpContent spawn = response.Content) { string content = await spawn.ReadAsStringAsync(); mServerCallback callback = Newtonsoft.Json.JsonConvert.DeserializeObject <mServerCallback>(content); if (callback.Status == "true") { return("true"); } return(callback.Mess); } } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); return(Strings.HttpFailed); } }
private async Task AddToCartActionAsync(Product product) { if (AccountService.Instance.Current_Account == null) { AccountService.Instance.autho(null, "Dismiss"); return; // Should stop catch error } if (IsBusy) { return; } IsBusy = true; try { DialogService.ShowLoading("Adding Item"); if (product.Status == "Out Of Stock") { DialogService.HideLoading(); DialogService.ShowErrorToast("Item Out Of Stock"); return; } mCartS cartItem = new mCartS() { ProductId = product.Id, Owner = AccountService.Instance.Current_Account.Email, Quantity = cQuantity }; var result = await CartService.Instance.Additem(cartItem); DialogService.HideLoading(); if (result == "true") { DialogService.ShowToast("Item Added To Cart"); } else { DialogService.ShowErrorToast("Failed To Add Item"); } } catch (Exception ex) { DialogService.ShowError(Strings.SomethingWrong); Debug.WriteLine(Keys.TAG + ex); Crashes.TrackError(ex); } finally { IsBusy = false; } }
private async Task QtyChgActionAsync(object itemName) { try { mCart listitem = (from itm in MyCartList where itm.Name == itemName.ToString() select itm) .FirstOrDefault <mCart>(); Product product = (from itm in MyProductList where itm.SummaryName == itemName.ToString() select itm) .FirstOrDefault <Product>(); var chg = await DialogService.ShowInputPrompt("Update", "Cancel", "Change Quantity", "Quantity", listitem.Quantity, InputType.Number); if (chg == null) { return; } if (Convert.ToInt16(chg) > Convert.ToInt16(product.Quantity)) { DialogService.ShowErrorToast("Max QTY is " + product.Quantity); return; } DialogService.ShowLoading("Updating Quantity"); mCartS updateCart = new mCartS() { Quantity = chg, Owner = AccountService.Instance.Current_Account.Email, ProductId = listitem.Id }; var result = await CartService.Instance.UpdateQuantity(updateCart); DialogService.HideLoading(); if (result == "true") { DialogService.ShowToast("Quantity Changed"); GetCart(); return; } DialogService.ShowError(result); } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowError(Strings.SomethingWrong); Crashes.TrackError(ex); } }
private async Task CartActionAsync(object itemName) { try { DialogService.ShowLoading("Adding To Cart"); mSavelaterR listitem = (from itm in MySaveList where itm.Name == itemName.ToString() select itm) .FirstOrDefault <mSavelaterR>(); mCartS item = new mCartS() { Owner = AccountService.Instance.Current_Account.Email, Quantity = "1", ProductId = listitem.Id }; var result = await SavelaterService.Instance.MvtoCart(item); DialogService.HideLoading(); if (result == "true") { GetSave(); return; } else { DialogService.ShowError(result); } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowError(Strings.SomethingWrong); Crashes.TrackError(ex); } }