public async Task <string> Additem(mUserItem 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 + "item/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); } }
public EditItem(mUserItem item) { viewModel = new Profile_EditItem_ViewModel(new PageService(Navigation), item); InitializeComponent(); Gestures(); }
public BuySell_ItemView_ViewModel(IPageService pageSerivce, mUserItem item, bool isList = false) { _pageService = pageSerivce; if (!isList) { BindContent(item); } if (AccountService.Instance.Current_Account != null) { if (item.Manufacturer == AccountService.Instance.Current_Account.Email) { IsBtnEnable = false; } } Itemid = item.Id; Owner = item.Manufacturer; SearchTxt = new Command(txt => SearchTxtAction(txt)); SearchCommand = new Command(() => { ShowSearchBar = !ShowSearchBar; }); AskQuestionCommand = new Command(() => AskQuestion()); ContactCommand = new Command(() => ContactSeller()); }
private async Task UpdateItemActionAsync(mUserItem item) { if (IsBusy) { return; } IsBusy = true; DialogService.ShowLoading("Updating item"); try { var result = await ItemService.Instance.UpdateItem(FormatItem(item)); DialogService.HideLoading(); if (result == "true") { DialogService.ShowToast("Item Updated"); await _pageService.PopAsync(); } else { DialogService.ShowError(result); } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowError(Strings.SomethingWrong); Crashes.TrackError(ex); } finally { IsBusy = false; } }
public Profile_EditItem_ViewModel(IPageService pageService, mUserItem item) { _pageService = pageService; ConnectFields(item); UpdateItemCommand = new Command(async() => await UpdateItemActionAsync(item)); DeleteItemCommand = new Command(async() => await DeleteItemAction(item)); }
public ItemView(mUserItem item) { _item = item; viewModel = new BuySell_ItemView_ViewModel(new PageService(Navigation), item); InitializeComponent(); SetStrings(); GetList(item); changeposit(); }
private void BindContent(mUserItem item) { try { ObservableCollection <mCarouselImage> images = new ObservableCollection <mCarouselImage>(); for (var i = 0; i < item.Images.Count; i++) { images.Add(new mCarouselImage() { Image = item.Images[i] }); } if (item.State == "New") { StateColor = "Green"; } else { StateColor = "Red"; } ItemImages = images; Name = item.Name; Price = item.Price; CreatedBy = item.Displayname; State = item.State; Quantity = item.Quantity; Status = item.Status; int max_description_length = 550; if (item.Description.Length > max_description_length) { Desc_isOverLoad = true; Description = item.Description.Substring(0, max_description_length) + "..."; } else { Description = item.Description; } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); } }
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { var item = e.SelectedItem as mSearchProduct; if (item != null) { mUserItem listitem = (from itm in viewModel.ItemList where itm.Name == item.bName select itm) .FirstOrDefault <mUserItem>(); Navigation.PushAsync(new ItemView(listitem)); } listView.SelectedItem = null; }
private void ConnectFields(mUserItem item) { ConnectImages(item.Images); Name = item.Name; Description = item.Description; Quantity = item.Quantity; Price = Price = Convert.ToString(Math.Truncate(Convert.ToDecimal(item.Price) * 100) / 100); ItemCreatedAt = "Created At: " + item.CreatedDate.Split('T')[0]; //for (var i = 0; i < Keys.ItemCategories.Count; i++) //{ // if (item.Category == Keys.ItemCategories[i]) // { // CategoryIndex = i; // break; // } //} for (var i = 0; i < Keys.ItemCategories.Count; i++) { if (item.Category == Keys.CatItems[Keys.ItemCategories[i]]) { CategoryIndex = i; break; } } for (var i = 0; i < _StateItems.Count; i++) { if (item.State == _StateItems[i]) { StateIndex = i; break; } } if (item.Visable == _VisableItems[1]) { VisableIndex = 1; } else { VisableIndex = 0; } }
public async Task <mUserItem> FetchItem(string Itemid) { try { var httpClient = new HttpClient(); var response = await httpClient.GetAsync(Keys.Url_Main + "item/" + Itemid); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); mServerCallback callback = Newtonsoft.Json.JsonConvert.DeserializeObject <mServerCallback>(content); if (callback.Status == "true") { mUserItem newitem = new mUserItem(); newitem = Newtonsoft.Json.JsonConvert.DeserializeObject <mUserItem>(callback.Data.ToString()); if (newitem == null) { return(null); } return(newitem); } else { DialogService.ShowError(Strings.ServerFailed); return(null); } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowErrorToast(Strings.HttpFailed); return(null); } }
private async Task DeleteItemAction(mUserItem item) { var response = await DialogService.DisplayAlert("Yes", "No", "Delete Item", "Are you sure?"); if (!response) { return; } try { if (IsBusy) { return; } IsBusy = true; DialogService.ShowLoading("Deleting Item"); var result = await ItemService.Instance.DeleteItem(item.Id); DialogService.HideLoading(); if (result == "true") { DialogService.ShowToast("Item Deleted"); return; } else { DialogService.ShowError(result); } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowError(Strings.SomethingWrong); Crashes.TrackError(ex); } finally { IsBusy = false; } }
private async void DeleteItemAction(object itemName) { var sure = await DialogService.DisplayAlert("Yes", "No", "Deleting Item", "Are you sure you want to delete the item"); if (!sure) { return; } try { mUserItem listitem = (from itm in MyItemList where itm.Name == itemName.ToString() select itm) .FirstOrDefault <mUserItem>(); MyItemList.Remove(listitem); OnPropertyChanged("RevMyItems"); var result = await ItemService.Instance.DeleteItem(listitem.Id); if (result == "true") { DialogService.ShowToast("Item Deleted"); Debug.WriteLine("DELETED"); return; } else { DialogService.ShowError(result); } } catch (Exception ex) { Debug.WriteLine(Keys.TAG + ex); DialogService.ShowError(Strings.SomethingWrong); Crashes.TrackError(ex); } }
public QuestionList(mUserItem item) { Item = item; viewModel = new BuySell_ItemView_ViewModel(new PageService(Navigation), item, true); InitializeComponent(); //viewModel.GetQuestionList(0, 10); viewModel.IsListRefereshing = true; listView.ItemSelected += ListView_ItemSelected; listView.ItemAppearing += (sender, e) => { if (viewModel.IsBusy || viewModel.Questionlist.Count < 4 || viewModel.isDone) { return; } if (e.Item == viewModel.Questionlist[viewModel.Questionlist.Count - 1]) { viewModel.GetQuestionList(viewModel.Questionlist.Count, 10, true);// add loader for viewmore on view } }; }
private async void GetList(mUserItem item) { PopulateQuestionList(await viewModel.FetchQuestionAction(null, item.Id, 0, 5)); getAds1(); }
private mUserItem FormatItem(mUserItem item) { var SelectedCategory = SelectedCat;//CategoryItems[CategoryIndex]; var SelectedState = StateItems[StateIndex]; var SelectedVisablity = VisableItems[VisableIndex]; item.Name = Name; item.Category = SelectedCategory; item.Price = Convert.ToString(Math.Truncate(Convert.ToDecimal(Price) * 100) / 100); item.Description = Description; item.Quantity = Quantity; item.State = SelectedState; if (SelectedVisablity == VisableItems[1]) { item.Visable = "false"; } else { item.Visable = "true"; } #region CheckingByte string[] curr_images = new string[4]; for (var i = 0; i < item.Images.Count; i++) { curr_images[i] = item.Images[i]; } if (bImg1 != null) { if (Img1 == "Remove") { curr_images[0] = "Remove"; } else { // ByteList.Add(bImg1); BytesItems[0] = bImg1; //item.Images[0] = null; curr_images[0] = null; } } if (bImg2 != null || Img2 == "Remove") { if (Img2 == "Remove") { curr_images[1] = "Remove"; } else { BytesItems[1] = bImg2; //item.Images[1] = null; curr_images[1] = null; //ByteList.Add(bImg2); } } if (bImg3 != null || Img3 == "Remove") { if (Img3 == "Remove") { curr_images[2] = "Remove"; } else { BytesItems[2] = bImg3; //item.Images[2] = null; curr_images[2] = null; //ByteList.Add(bImg3); } } if (bImg4 != null || Img4 == "Remove") { if (Img4 == "Remove") { curr_images[3] = "Remove"; } else { //ByteList.Add(bImg4); BytesItems[3] = bImg4; //item.Images[3] = null; curr_images[3] = null; } } List <string> loopedImages = new List <string>(); for (var i = 0; i < curr_images.Length; i++) { loopedImages.Add(curr_images[i]); } #endregion item.Images = loopedImages; item.bImages = BytesItems; if (item.Images[0] != null) { if (item.Images[0] != "Remove") { item.Thumbnail = new Uri(item.Thumbnail).AbsolutePath.Split('/')[2]; } } for (int i = 0; i < item.Images.Count; i++) { if (item.Images[i] != null) { if (item.Images[i] != "Remove") { item.Images[i] = new Uri(item.Images[i]).AbsolutePath.Split('/')[2]; } } } return(item); }
private async void AddItemAction() { var SelectedCategory = SelectedCat; //CategoryItems[CategoryIndex];// var SelectedState = StateItems[StateIndex]; if (IsBusy) { return; } IsBusy = true; DialogService.ShowLoading("Adding Item"); try { if (!secondtime) { GetImgBytes(); } if (!(ByteList.Count > 0)) { DialogService.ShowError("Please Add Atleast one image"); return; } var theimages = ByteList; mUserItem item = new mUserItem() { Name = Title, Description = Description, Category = SelectedCategory, Quantity = Quantity, State = SelectedState, Price = Convert.ToString(Math.Truncate(Convert.ToDecimal(FixedPricer) * 100) / 100), bImages = theimages, Manufacturer = AccountService.Instance.Current_Account.Email, Displayname = "..." }; if (!String.IsNullOrEmpty(AccountService.Instance.Current_Account.Displayname)) { item.Displayname = AccountService.Instance.Current_Account.Displayname; } var result = await ItemService.Instance.Additem(item); DialogService.HideLoading(); if (result == "true") { DialogService.ShowSuccess("Item Added"); await _pageService.PopAsync(); } else { DialogService.ShowError(result); secondtime = true; } } catch (Exception ex) { DialogService.ShowError(Strings.SomethingWrong); Debug.WriteLine(Keys.TAG + ex); Crashes.TrackError(ex); } finally { IsBusy = false; } }