Пример #1
0
 public MarketPage()
 {
     InitializeComponent();
     this.BindingContext = viewModel = new MarketPageViewModel();
     LV.ItemTapped      += LV_ItemTapped;
     postItemService     = DependencyService.Get <ILiquidationPostItemService>();
     Init();
 }
        public async Task <bool> Follow(string PostId)
        {
            ILiquidationPostItemService postItemService = DependencyService.Get <ILiquidationPostItemService>();
            var isFollow = await postItemService.Follow(PostId, UserLogged.Id);

            var currentPost = this.Data.Where(x => x.Id == PostId).SingleOrDefault();

            if (currentPost != null)
            {
                currentPost.IsFollow = isFollow;
            }
            return(isFollow);
        }
Пример #3
0
        private async void Save_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(EntryTitle.Text))
            {
                await DisplayAlert("", Language.vui_long_nhap_tieu_de_bai_dang, Language.dong);

                return;
            }
            if (string.IsNullOrEmpty(editor.Text))
            {
                await DisplayAlert("", Language.vui_long_nhap_mo_ta_bai_dang, Language.dong);

                return;
            }

            loadingPopup.IsVisible = true;
            MultipartFormDataContent form = new MultipartFormDataContent();

            string[] imageList = null;

            // kiem tra co hinh thi upload.
            if (viewModel.Media.Count > 0)
            {
                if (viewModel.Media.Count > 9)
                {
                    loadingPopup.IsVisible = false;
                    await DisplayAlert("", Language.vui_long_chon_toi_da_9_anh, Language.dong);

                    return;
                }

                imageList = new string[viewModel.Media.Count];
                for (int i = 0; i < viewModel.Media.Count; i++)
                {
                    var media = viewModel.Media[i];
                    // chua upload. upload roi link = null
                    if (string.IsNullOrEmpty(media.Path) == false) // co link la co chon tu dien thoai.
                    {
                        imageList[i] = $"{Guid.NewGuid().ToString()}.jpg";
                        var stream  = new System.IO.MemoryStream(File.ReadAllBytes(media.Path));
                        var content = new StreamContent(stream);
                        content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                        {
                            Name     = "files" + i,
                            FileName = imageList[i]
                        };
                        form.Add(content);
                    }
                }

                var uploadResponse = await UploadImage(form);

                if (uploadResponse.IsSuccess == false)
                {
                    loadingPopup.IsVisible = false;
                    await DisplayAlert("", Language.loi_upload_hinh_anh_vui_long_thu_lai, Language.dong);

                    return;
                }
            }

            LiquidationPostItem item = new LiquidationPostItem();

            item.Title       = EntryTitle.Text;
            item.Type        = ControlSegment.GetCurrentIndex();
            item.Description = editor.Text;
            item.Images      = imageList;
            item.CreatedById = UserLogged.Id;
            item.CreatedBy   = new PostItemUser()
            {
                UserId   = UserLogged.Id,
                FullName = UserLogged.FullName,
                Avatar   = UserLogged.AvatarUrl.Replace(ApiConfig.IP2, "")
            };
            item.CreatedDate = DateTime.Now;
            item.HasImage    = imageList != null && imageList.Length > 0;

            if (EntryPrice.Text.HasValue)
            {
                item.HasPrice = true;
                item.Price    = DecimalHelper.ToCurrency(EntryPrice.Text.Value) + " đ";
            }

            if (viewModel.Province != null)
            {
                item.ProvinceId = viewModel.Province.Id;
                if (viewModel.District != null)
                {
                    item.DistrictId = viewModel.District.Id;
                    if (viewModel.Ward != null)
                    {
                        item.WardId = viewModel.Ward.Id;
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(viewModel.Address))
            {
                item.HasAddress = true;
                item.Address    = viewModel.Address;
            }

            if (viewModel.Category != null)
            {
                item.HasCategory  = true;
                item.CategoryName = viewModel.Category.Name;
            }

            ILiquidationPostItemService postItemService = DependencyService.Get <ILiquidationPostItemService>();

            postItemService.AddPostItem(item);
            MessagingCenter.Send <AddPostItemPage, LiquidationPostItem>(this, "AddPostItemSuccess", item);
            loadingPopup.IsVisible = false;
            await Navigation.PopAsync();
        }