예제 #1
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);

            FurniturePostItem post = (FurniturePostItem)(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 FurniturePostItemDetailPage(FurniturePostItem postItem)
 {
     InitializeComponent();
     this.BindingContext = viewModel = new FurniturePostItemDetailPageViewModel();
     viewModel.PostItem  = postItem;
     Init();
 }
예제 #3
0
 public void AddPostItem(FurniturePostItem postItem)
 {
     postItem.UserComments = new List <string>()
     {
         postItem.CreatedById
     };
     this._postItems.InsertOne(postItem);
 }
예제 #4
0
        public async Task <string[]> GetReceiveNotificationUser(string PostId)
        {
            FurniturePostItem 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());
        }
예제 #5
0
        public async Task <bool> Follow(string PostId, string UserId)
        {
            FurniturePostItem 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.VIewFurniturePostItem,
                    PostItemId        = PostId,
                    CreatedDate       = DateTime.Now,
                    IsRead            = false,
                    Thumbnail         = NotificationImage
                };
                await notificationService.AddNotification(notification, Language.theo_doi);

                return(true);
            }
        }
        private async void Save_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(EntryTitle.Text))
            {
                await DisplayAlert("", Language.vui_long_nhap_tieu_de, 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;
                }
            }

            FurniturePostItem item = new FurniturePostItem();

            item.Title       = EntryTitle.Text.Trim();
            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.ParentCategory != null)
            {
                item.HasParentCategory  = true;
                item.ParentCategoryName = viewModel.ParentCategory.Name;
            }

            if (viewModel.ChildCategory != null)
            {
                item.HasChildCategory  = true;
                item.ChildCategoryName = viewModel.ChildCategory.Name;
            }

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

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