public ActionResult SaveNotification(Notification notification) { try { _notifyService.SaveNotification(notification); } catch (Exception ex) { Log.Error(ex, $"Something went wrong during {nameof(SaveNotification)} operation."); } return(StatusCode(201)); }
public async Task <ActionResult> SaveUserMessage(UserMessages message) { try { if (message == null) { throw new ArgumentNullException( MessagingConstants.MessageObjectWrongValue(nameof(message), message)); } Notification not = new Notification() { ActivityType = (int)ActivityTypes.Message, ActivityToUserId = message.ToUserId, ActivityFromUserId = message.FromUserId, IsAcknowledged = false, NotificationBody = message.MessageContent, }; // save whole user message message.MessageId = _messagingService.SaveUserMessage(message); not.MessageId = message.MessageId; // call notification repo and save the new activity, get notification id not.NotificationId = _notifyService.SaveNotification(not); //prepare notification info data for pusher api connection var notificationInfo = new { Data = not, MainMessage = not.NotificationBody }; // send the notification to the target user (be sure send through the channel dedicated for user - unlimited channels) await _pusherChannel .Trigger(notificationInfo, PusherConstants.CHANNEL_MESSAGING, $"{PusherConstants.MESSAGING_EVENT}_{message.ToUserId}"); return(StatusCode(201)); } catch (DbUpdateException) { return(StatusCode(507)); } catch (ArgumentNullException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }