/// <summary> /// Broadcast New Like Price /// </summary> private void SqlLikesTableDependencyChanged(object sender, RecordChangedEventArgs <Like> e) { if (e.ChangeType == ChangeType.Insert || e.ChangeType == ChangeType.Update) { var userProfileActor = _userProfileService.GetUserProfile(e.Entity.UserProfileId); var post = _postService.GetPost(e.Entity.PostId); var userProfileTarget = _userProfileService.GetUserProfile(post.UserProfile.Id); Notification notification = null; if (e.Entity.Value == 1) { notification = _notificationService.AddNotification(userProfileTarget.Id, userProfileActor.Name + " liked your post", "", userProfileActor.Name + " liked your post. Click to see your post", "/posts/" + post.Id); } else { notification = _notificationService.AddNotification(userProfileTarget.Id, userProfileActor.Name + " disliked your post", "", userProfileActor.Name + " disliked your post. Click to see your post", "/posts/" + post.Id); } if (notification != null) { var test = GlobalHost.DependencyResolver.Resolve <IConnectionManager>() .GetHubContext <LikeWatcherHub>(); LikeWatcherHub.PushNotification(notification, userProfileTarget.Id); } } }
public async Task AddNotification() { IMongoDatabase database = await InitializeDatabaseWithNotifications(_mongoClient, TestingDatabaseName); var notificationService = new NotificationService(database); var newNotification = new SimpleMessageNotification() { Id = Guid.NewGuid(), RecipientId = TestStudentGuid, Type = NotificationType.SimpleMessageNotification, Message = "nova notifikacia", Read = true }; await notificationService.AddNotification(newNotification); var notifications = (await notificationService.GetStudentNotifications(TestStudentGuid)).ToList(); notifications.Should().BeEquivalentTo( _notifications.Concat(new List <Notification>() { newNotification })); await _mongoClient.DropDatabaseAsync(TestingDatabaseName); }
public ActionResult Post(Book book) { ActionResult response = BadRequest("invalid data"); Transaction transaction = _patientService.Book(book); if (transaction != null) { UserProfileModel userProfile = _userService.GetUserProfile(book.patientId); Data data = new Data { Id = book.patientId, Image = userProfile.Image, Lat = book.location.lat, Long = book.location.longt, Name = userProfile.Fname + " " + userProfile.Lname, Tans_Id = transaction.Id, body = "waiting to approve your request", title = "You have a request" }; _notificationService.SendNotification(_userService.GetTokens(book.doctorId), data); _notificationService.AddNotification(new Notification { Date = DateTime.Now, Message = "waiting to approve your request", Read = true, Tans_Id = transaction.Id, UserFrom_Id = book.patientId, UserTo_Id = book.doctorId }); response = Ok(); } return(response); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AcceptRequest_Click(object sender, RoutedEventArgs e) { var request = datagrid.SelectedItem as Request.Request; RequestsService.ChangeRequestsStatus(request, State.Accepted); NotificationService.AddNotification(request, "Администратор принял вашу заявку"); }
public async Task <IActionResult> AddNotification(DTONotification notification) { bool success = await _service.AddNotification(notification); if (success) { return(Ok()); } else { return(BadRequest()); } }
/// <summary> /// Call this method from UI thread. It has code at the beginning which needs to run /// in UI thread and then awaits the async operation. /// </summary> /// <param name="asyncAction"></param> /// <returns></returns> public static async Task <bool> StartActionWithProgress(Func <CancellationToken, Task> asyncAction, bool sendNotificationOnError = true) { bool error = false; var dialogServiceVm = DependencyContainer.Get <DialogServiceViewModel>(); NotificationService notificationService = null; if (sendNotificationOnError) { notificationService = DependencyContainer.Get <NotificationService>(); } CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken ct = cts.Token; ProgressDialogViewModel progressVm = new ProgressDialogViewModel(cts); dialogServiceVm.ShowProgressDialog(progressVm); try { await asyncAction(ct); } catch (Exception ex) { error = true; if (sendNotificationOnError) { Notification notification = new Notification(NotificationTypeEnum.Error, "Operation failed.", ex); notificationService.AddNotification(notification); } else { throw; } } finally { progressVm.OperationEnded = true; } if (error) { return(false); } return(true); }
public async Task AddNotification_ShouldAddNotificationInRepository() { // Arrange var person = new PersonBuilder().WithId(1).Build(); var employer = new EmployerBuilder().WithId(1).Build(); var job = new JobBuilder().WithId(1).Build(); var notification = new NotificationBuilder().WithId(1).WithEmployer(employer).WithPerson(person) .WithJob(job).Build(); // Act await _notificationService.AddNotification(notification); // Assert _notificationRepositoryMock.Verify(n => n.AddNotification(notification), Times.Once); _notificationRepositoryMock.Verify(m => m.SaveAsync(), Times.Once()); }
public ActionResult GetRespose(int transaction, bool status) { ActionResult respose = BadRequest("invalid Id"); Transaction Mytransaction = _doctorService.Response(transaction, status); if (Mytransaction != null) { UserProfileModel userProfile = _userService.GetUserProfile(Mytransaction.Doctor_Id); Data data = new Data { Id = Mytransaction.Doctor_Id, Image = userProfile.Image, Lat = "jjj", Long = "jjg", Name = userProfile.Fname + " " + userProfile.Lname, Tans_Id = Mytransaction.Id }; if ((bool)Mytransaction.Accepted) { data.body = "Approved Your Request"; data.title = "You have new notification"; _notificationService.SendNotification(_userService.GetTokens(Mytransaction.Patient_Id), data); } else { data.body = "Refused Your Request"; data.title = "You have new notification"; _notificationService.SendNotification(_userService.GetTokens(Mytransaction.Patient_Id), data); } _notificationService.AddNotification(new Notification { Date = DateTime.Now, Message = "waiting for approving your request", Read = true, Tans_Id = transaction, UserFrom_Id = Mytransaction.Doctor_Id, UserTo_Id = Mytransaction.Patient_Id }); respose = Ok(); } return(respose); }
public async Task <NotificationAddViewModel> Post([FromBody] NotificationAddViewModel newNotification) { var user = await _accountManager.GetUserByIdAsync(newNotification.ownerId); var notification = new Notification { Body = newNotification.Body, BuildingEntranceId = newNotification.BuildingEntranceId, BuildingFloorId = newNotification.BuildingFloorId, BuildingId = newNotification.BuildingId, Creator = user, Date = DateTime.Now, Header = newNotification.Header, HaveDeadline = newNotification.haveDeadline, Deadline = newNotification.deadline }; notification = _notificationService.AddNotification(notification); newNotification.Id = notification.Id; return(newNotification); }
public void AddNotification(Notification notification) { _notificationService.AddNotification(notification); }
public JsonResult AddNotification(int userId, int friendId) { _notificationService.AddNotification(userId, friendId, NotificationTypeEnum.RequestAddFriend, 0, "", null); return(Json(true, JsonRequestBehavior.AllowGet)); }
private async void Save_Appointment_Clicked(object sender, EventArgs e) { if (EntryFullName.IsVisible && string.IsNullOrWhiteSpace(EntryFullName.Text)) { await DisplayAlert("", "Nhập họ tên", Language.dong); return; } if (EntryPhone.IsVisible && string.IsNullOrWhiteSpace(EntryPhone.Text)) { await DisplayAlert("", "Nhập số điện thoại", Language.dong); return; } loadingPopup.IsVisible = true; viewModel.Appointment.BuyerFullName = EntryFullName.Text; viewModel.Appointment.BuyerEmail = EntryEmail.Text; viewModel.Appointment.BuyerPhone = EntryPhone.Text; viewModel.Appointment.Description = EdtDescription.Text; viewModel.Appointment.Date = calendar.SelectedDate; ApiResponse response = null; Guid SaveId = Guid.Empty; Guid ReceiverId = Guid.Empty; string ReceiverToken = string.Empty; if (viewModel.Appointment.OwnerId == Guid.Parse(UserLogged.Id)) // toi la nguoi ban - toi them/sua { ReceiverId = viewModel.Appointment.BuyerId; ReceiverToken = viewModel.Appointment.Buyer.FirebaseRegToken; } else { ReceiverId = viewModel.Appointment.OwnerId; ReceiverToken = viewModel.Appointment.Owner.FirebaseRegToken; } if (viewModel.Appointment.Id == Guid.Empty) { response = await ApiHelper.Post("api/appointment", viewModel.Appointment, true); } else { response = await ApiHelper.Put("api/appointment", viewModel.Appointment, true); } if (response.IsSuccess) { NotificationService notificationService = new NotificationService(); string message = string.Empty; if (viewModel.Appointment.Id == Guid.Empty) { SaveId = Guid.Parse(response.Content.ToString()); message = UserLogged.FullName + " đã đăt một cuộc hẹn với bạn"; } else { message = UserLogged.FullName + " đã cập nhật lịch hẹn"; SaveId = _id; } var notification = new NotificationModel() { UserId = ReceiverId, CurrentBadgeCount = (int)notificationService.CountNotReadNotificationUser(ReceiverId) + 1, Title = message, NotificationType = NotificationType.ViewAppointment, AppointmentId = SaveId, CreatedDate = DateTime.Now, IsRead = false, Thumbnail = viewModel.Appointment.Post.AvatarFullUrl }; await notificationService.AddNotification(notification, Language.lich); loadingPopup.IsVisible = false; if (viewModel.Appointment.Id == Guid.Empty) { await DisplayAlert("", "Đặt lịch thành công", Language.dong); await Navigation.PopAsync(); } else { await DisplayAlert("", "Cập nhật lịch thành công", Language.dong); } } else { loadingPopup.IsVisible = false; await DisplayAlert("", response.Message, Language.dong); } }