public B2BDetailPage(B2BPostItem postItem)
 {
     InitializeComponent();
     this.BindingContext = viewModel = new B2BDetailPageViewModel();
     viewModel.PostItem  = postItem;
     Init();
 }
Ejemplo n.º 2
0
        private async void FollowPost_Clicked(object sender, EventArgs e)
        {
            loadingPopup.IsVisible = true;
            if (UserLogged.IsLogged == false)
            {
                loadingPopup.IsVisible = false;
                await DisplayAlert("", Language.vui_long_dang_nhap, Language.dong);

                ((AppShell)Shell.Current).SetLoginPageActive();
                return;
            }

            Grid grid = (sender as Grid);

            B2BPostItem post = (B2BPostItem)(grid.GestureRecognizers[0] as TapGestureRecognizer).CommandParameter;

            if (post.CreatedById == UserLogged.Id)
            {
                loadingPopup.IsVisible = false;
                await DisplayAlert("", Language.khong_the_thuc_hien_chuc_nang_nay, Language.dong);

                return;
            }

            bool isFollow = await viewModel.Follow(post.Id);

            grid.Children[2].IsVisible = isFollow;
            grid.Children[3].IsVisible = isFollow;
            loadingPopup.IsVisible     = false;
        }
 public void AddPostItem(B2BPostItem postItem)
 {
     postItem.UserComments = new List <string>()
     {
         postItem.CreatedById
     };
     this._postItems.InsertOne(postItem);
 }
        public async Task <string[]> GetReceiveNotificationUser(string PostId)
        {
            B2BPostItem post = await this.GetById(PostId);

            var followList   = post.UserFollows ?? new List <string>();
            var commentArray = post.UserComments.ToArray();

            foreach (var item in commentArray)
            {
                if (!followList.Any(x => x == item))
                {
                    followList.Add(item);
                }
            }
            return(followList.ToArray());
        }
        public async Task <bool> Follow(string PostId, string UserId)
        {
            B2BPostItem post = _postItems.Find(x => x.Id == PostId).SingleOrDefault();

            if (post.UserFollows != null && post.UserFollows.Any(x => x == UserId)) // dang follow
            {
                post.UserFollows.Remove(UserId);
                _postItems.ReplaceOne(p => p.Id == PostId, post);
                return(false);
            }
            else
            {
                if (post.UserFollows == null)
                {
                    post.UserFollows = new List <string>();
                }

                post.UserFollows.Add(UserId);
                _postItems.ReplaceOne(p => p.Id == PostId, post);

                // send notifiaction.
                INotificationService notificationService = DependencyService.Get <INotificationService>();
                Guid ReceiverId = Guid.Parse(post.CreatedById);

                string            NotificationImage = (post.Images != null && post.Images.Length > 0) ? AvatarHelper.GetPostAvatar(post.Images.FirstOrDefault()) : null;
                NotificationModel notification      = new NotificationModel()
                {
                    UserId            = ReceiverId,
                    CurrentBadgeCount = (int)notificationService.CountNotReadNotificationUser(ReceiverId) + 1,
                    Title             = UserLogged.FullName + " đã theo dõi bài viết của bạn",
                    NotificationType  = NotificationType.ViewB2BPostItem,
                    PostItemId        = PostId,
                    CreatedDate       = DateTime.Now,
                    IsRead            = false,
                    Thumbnail         = NotificationImage
                };
                await notificationService.AddNotification(notification, Language.theo_doi);

                return(true);
            }
        }
Ejemplo n.º 6
0
        private async void Save_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(EntryTitle.Text))
            {
                await DisplayAlert("", Language.vui_long_nhap_tieu_de, Language.dong);

                return;
            }
            else if (string.IsNullOrWhiteSpace(editor.Text))
            {
                await DisplayAlert("", Language.vui_long_nhap_noi_dung, Language.dong);

                return;
            }


            loadingPopup.IsVisible = true;
            // 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;
                }

                List <MediaFile> listUploadMedia = viewModel.Media.Where(x => x.Path != null).ToList();
                if (listUploadMedia.Any())
                {
                    MultipartFormDataContent form = new MultipartFormDataContent();
                    for (int i = 0; i < listUploadMedia.Count; i++)
                    {
                        string imageName = $"postitem_{Guid.NewGuid().ToString()}.jpg";
                        ImageList.Add(imageName);

                        var media   = listUploadMedia[i];
                        var stream  = new MemoryStream(File.ReadAllBytes(media.Path));
                        var content = new StreamContent(stream);
                        content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                        {
                            Name     = "files" + i,
                            FileName = imageName
                        };
                        form.Add(content);
                    }

                    var uploadResonse = await UploadImage(form);

                    if (!uploadResonse.IsSuccess)
                    {
                        loadingPopup.IsVisible = false;
                        await DisplayAlert("", uploadResonse.Message, Language.dong);

                        return;
                    }
                }
            }

            #region address

            List <string> addressList = new List <string>();
            if (!string.IsNullOrWhiteSpace(EntryStreet.Text))
            {
                addressList.Add(EntryStreet.Text.Trim());
            }

            if (viewModel.Ward != null)
            {
                addressList.Add(viewModel.Ward.Name);
            }

            if (viewModel.District != null)
            {
                addressList.Add(viewModel.District.Name);
            }

            if (viewModel.Province != null)
            {
                addressList.Add(viewModel.Province.Name);
            }
            string Address = string.Join(", ", addressList.ToArray());
            #endregion



            B2BPostItem item = new B2BPostItem();
            //item.Type = SegmentType.SelectedIndex;
            item.Type        = ControlSegment.GetCurrentIndex();
            item.Title       = EntryTitle.Text.Trim();
            item.Description = editor.Text.Trim();
            item.Images      = ImageList.Any() ? ImageList.ToArray() : null;
            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.Count() > 0;

            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;
                    }
                }
            }

            item.Address    = Address;
            item.HasAddress = !string.IsNullOrWhiteSpace(Address);

            #region price
            if (SwitchIsNegotiate.IsToggled)
            {
                item.HasPrice  = true;
                item.PriceText = Language.thoa_thuan;
            }
            else
            {
                List <string> PriceList = new List <string>();
                if (SwitchIsPriceRange.IsToggled)
                {
                    if (EntryPriceFrom.Text.HasValue && EntryPriceFrom.Text.Value > 0)
                    {
                        PriceList.Add(string.Format("{0:0,0 đ}", EntryPriceFrom.Text));
                    }

                    if (EntryPriceTo.Text.HasValue && EntryPriceTo.Text.Value > 0)
                    {
                        PriceList.Add(string.Format("{0:0,0 đ}", EntryPriceTo.Text));
                    }
                }
                else
                {
                    if (EntryPrice.Text.HasValue && EntryPrice.Text.Value > 0)
                    {
                        PriceList.Add(string.Format("{0:0,0 đ}", EntryPrice.Text));
                    }
                }

                if (PriceList.Any())
                {
                    item.HasPrice  = true;
                    item.PriceText = string.Join(" - ", PriceList.ToArray());
                }
            }
            #endregion

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

            ToastMessageHelper.ShortMessage(Language.dang_thanh_cong);
        }