public async Task <ISocialResponse> AddNotificationActivityAsync(int userId, ActionType actionId, string parentPostId, ParentType parentTypeId, int senderUserId, string notifyText, string roomId) { try { //logger.Info($"{ GetType().Name} { ExtensionUtility.GetCurrentMethod() } userId: {userId}"); var notificationGenericObject = await _mongoDbContext.NotificationGenericObjects.Find(x => x.UserID == userId).FirstOrDefaultAsync() ?? await AddNotificationObjectAsync(userId); var notificationObj = new Notification { ID = ObjectId.GenerateNewId(), ActionID = (int)actionId, IsRead = false, ParentID = parentPostId, ParentTypeID = (int)parentTypeId, SenderID = senderUserId, IsPushed = true //PostTypeID = typeId }; notificationGenericObject.Notifications.Add(notificationObj); if (userId != senderUserId) { notificationGenericObject.UnseenNotificationCounter += 1; var notificationView = _mapper.Map <NotificationView>(notificationObj); await FillNotificationUserDetailsAsync(userId, new List <NotificationView>() { notificationView }, roomId); var deviceIds = await _appDbContext.UserDeviceInfos.Where(k => k.UserId == userId).Select(k => k.DeviceId).ToListAsync(); foreach (var deviceId in deviceIds) { await _pushNotificationService.SendRecommendPushNotificationAsync(notificationView, notifyText, deviceId); } logger.Info("Notification sent"); } await _mongoDbContext.NotificationGenericObjects.ReplaceOneAsync(x => x.UserID == userId, notificationGenericObject); var notificationGenericObjectView = new NotificationGenericObjectView { ID = notificationGenericObject.ID.ToString(), UserID = notificationGenericObject.UserID, UnseenNotificationCounter = notificationGenericObject.UnseenNotificationCounter, NotificationsList = _mapper.Map <List <NotificationView> >(notificationGenericObject.Notifications) }; return(new SocialResponse(notificationGenericObjectView)); } catch (Exception e) { logger.Error(e); return(new SocialResponse(e)); } }
public async Task <IUserRecommendationResponse> AddNotificationAsync(int recipientUserID, ActionType actionId, int recommendId, ParentType parentTypeId, int senderUserId, string notifyText) { try { logger.Info($"{ GetType().Name} { ExtensionUtility.GetCurrentMethod() } userId: {senderUserId} UserIPAddress: { _userIPAddress.GetUserIP().Result }"); //var profileId = userId != senderUserId ? senderUserId : userId; var notificationGenericObject = await _mongoDbContext.NotificationGenericObjects.Find(x => x.UserID == recipientUserID).FirstOrDefaultAsync() ?? await AddNotificationObjectAsync(recipientUserID); var notificationObj = new Notification { ID = ObjectId.GenerateNewId(), ActionID = (int)actionId, IsRead = false, ParentID = recommendId.ToString(), ParentTypeID = (int)parentTypeId, SenderID = senderUserId }; notificationGenericObject.Notifications.Add(notificationObj); //if (userId != senderUserId) //{ notificationGenericObject.UnseenNotificationCounter += 1; var notificationView = _mapper.Map <NotificationView>(notificationObj); await FillNotificationUserDetailsAsync(recipientUserID, new List <NotificationView>() { notificationView }); var deviceIds = await _appDbContext.UserDeviceInfos.Where(k => k.UserId == recipientUserID).Select(k => k.DeviceId).ToListAsync(); foreach (var deviceId in deviceIds) { await _pushNotificationService.SendRecommendPushNotificationAsync(notificationView, notifyText, deviceId); } logger.Info("Notification sent"); //} await _mongoDbContext.NotificationGenericObjects.ReplaceOneAsync(x => x.UserID == recipientUserID, notificationGenericObject); var notificationGenericObjectView = new NotificationGenericObjectView { ID = notificationGenericObject.ID.ToString(), UserID = notificationGenericObject.UserID, UnseenNotificationCounter = notificationGenericObject.UnseenNotificationCounter, NotificationsList = _mapper.Map <List <NotificationView> >(notificationGenericObject.Notifications) }; return(new UserRecommendationResponse(notificationGenericObjectView)); } catch (Exception e) { return(new UserRecommendationResponse(e)); } }
//public async Task<bool> PushNotification(NotificationView notification, string notifyText, int userId) //{ // var deviceIds = await _appDbContext.UserDeviceInfos.Where(k => k.UserId == userId).Select(k => k.DeviceId).ToListAsync(); // foreach (var deviceId in deviceIds) // { // await _pushNotificationService.SendRecommendPushNotificationAsync(notification, notifyText, deviceId); // } // return true; //} public async Task <ISocialResponse> AddPushNotificationAsync(int userId, Notification obj) { try { //logger.Info($"{ GetType().Name} { ExtensionUtility.GetCurrentMethod() } userId: {userId}"); var notificationGenericObject = await _mongoDbContext.NotificationGenericObjects.Find(x => x.UserID == userId).FirstOrDefaultAsync() ?? await AddNotificationObjectAsync(userId); var Notifications = notificationGenericObject.Notifications.FirstOrDefault(o => o.ID == obj.ID && o.IsPushed == false); if (Notifications != null) { obj.IsPushed = true; // await _mongoDbContext.notificationGenericObject.ReplaceOneAsync(x => x.ID == view.MeetupId, genericObject); if (userId != obj.SenderID) { notificationGenericObject.UnseenNotificationCounter += 1; var notificationView = _mapper.Map <NotificationView>(obj); await FillNotificationUserDetailsAsync(userId, new List <NotificationView>() { notificationView }, ""); //var deviceIds = await _appDbContext.UserDeviceInfos.Where(k => k.UserId == userId).Select(k => k.DeviceId).ToListAsync(); //foreach (var deviceId in deviceIds) //{ // await _pushNotificationService.SendPushNotificationAsync(notificationView, deviceId); //} PushNotification(notificationView, userId); logger.Info("Notification sent"); } notificationGenericObject.Notifications.Remove(Notifications); notificationGenericObject.Notifications.Add(obj); await _mongoDbContext.NotificationGenericObjects.ReplaceOneAsync(x => x.UserID == userId, notificationGenericObject); } var notificationGenericObjectView = new NotificationGenericObjectView { ID = notificationGenericObject.ID.ToString(), UserID = notificationGenericObject.UserID, UnseenNotificationCounter = notificationGenericObject.UnseenNotificationCounter, NotificationsList = _mapper.Map <List <NotificationView> >(notificationGenericObject.Notifications) }; return(new SocialResponse(notificationGenericObjectView)); } catch (Exception e) { logger.Error(e); return(new SocialResponse(e)); } }
public SocialResponse(NotificationGenericObjectView view) : this(true, string.Empty, view) { }
private SocialResponse(bool success, string message, NotificationGenericObjectView view) : base(success, message) { NotificationGenericObject = view; }
public UserRecommendationResponse(NotificationGenericObjectView view) : this(true, string.Empty, view) { }
private UserRecommendationResponse(bool success, string message, NotificationGenericObjectView view) : base(success, message) { NotificationGenericObject = view; }