private async void ShowComment_Clicked(object sender, EventArgs e) { if (!UserLogged.IsLogged) { await DisplayAlert("", Language.vui_long_dang_nhap, Language.dong); ((AppShell)Shell.Current).SetLoginPageActive(); } else { EditorComment.Focus(); } }
private async void SendComment_Clicked(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(viewModel.CommentText) && viewModel.CommentPosts.Any() == false) { await DisplayAlert("", Language.nhap_binh_luan_hoac_chon_tin_dang_de_gui_binh_luan, Language.dong); return; } loadingPopup.IsVisible = true; PostItemComment comment = new PostItemComment(); if (!string.IsNullOrWhiteSpace(viewModel.CommentText)) { comment.HasText = true; comment.Text = viewModel.CommentText.Trim(); } comment.PostItemId = viewModel.PostItem.Id; comment.CreatedDate = DateTime.Now; comment.CreatedById = UserLogged.Id; comment.CreatedBy = new PostItemUser() // them cho nay de giao dien co. ko luu db. { UserId = UserLogged.Id, FullName = UserLogged.FullName, Avatar = UserLogged.AvatarUrl // neu la lnk full thi avatar full url tra ve nguyen ven. }; if (viewModel.CommentPosts.Any()) { comment.HasPost = true; comment.Posts = viewModel.CommentPosts.ToList(); } viewModel.InsertComment(comment); viewModel.Comments.Insert(0, comment); CancelCommnet_Clicked(sender, EventArgs.Empty); EditorComment.Unfocus(); loadingPopup.IsVisible = false; try { INotificationService notificationService = DependencyService.Get <INotificationService>(); var AllUserReceiveNoti = await viewModel._postItemService.GetReceiveNotificationUser(viewModel.PostItem.Id); //var allUserFollow = string[] CommentUserIds = AllUserReceiveNoti.Where(x => x != UserLogged.Id).ToArray(); string NotificationTitle = UserLogged.FullName + Language.da_binh_luan_trong_bai_viet; string NotificationImage = (viewModel.PostItem.Images != null && viewModel.PostItem.Images.Length > 0) ? AvatarHelper.GetPostAvatar(viewModel.PostItem.Images.FirstOrDefault()) : ""; foreach (var userIdComment in CommentUserIds) { Guid ReceiverId = Guid.Parse(userIdComment); NotificationModel notification = new NotificationModel() { UserId = ReceiverId, CurrentBadgeCount = (int)notificationService.CountNotReadNotificationUser(ReceiverId) + 1, Title = NotificationTitle, NotificationType = NotificationType.ViewInternalPostItem, PostItemId = viewModel.PostItem.Id, CreatedDate = DateTime.Now, IsRead = false, Thumbnail = NotificationImage }; await notificationService.AddNotification(notification, Language.binh_luan); } } catch (Exception ex) { await DisplayAlert("", Language.co_loi_khi_gui_thong_bao, Language.dong); } }