public ActionResult <List <UserMessages> > GetUserMessagesByAdvertismentId(int advertId, string currentUserId) { try { ArgumentsValidator.Validate(nameof(currentUserId), currentUserId); if (advertId < 1) { throw new ArgumentException( MessagingConstants.MessageArgumentWrongValue(nameof(advertId), advertId)); } var response = _messagingService.GetUserMessagesByAdvertismentId(advertId, currentUserId); return(StatusCode(200, response)); } catch (ArgumentNullException) { return(StatusCode(400)); } catch (ArgumentException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }
public ActionResult DeleteUserMessage(int messageId) { try { if (messageId < 1) { throw new ArgumentException( MessagingConstants.MessageArgumentWrongValue(nameof(messageId), messageId)); } _messagingService.DeleteUserMessage(messageId); return(StatusCode(200)); } catch (DbUpdateException) { return(StatusCode(507)); } catch (MessageNotFoundException) { return(StatusCode(404)); } catch (Exception) { return(StatusCode(500)); } }
public ActionResult UpdateMessageReadStatus(int messageId, bool newReadStatus) { try { if (messageId < 1) { throw new ArgumentException( MessagingConstants.MessageArgumentWrongValue(nameof(messageId), messageId)); } _messagingService.UpdateMessageReadStatus(messageId, newReadStatus); return(StatusCode(204)); } catch (MessageNotFoundException) { return(StatusCode(404)); } catch (ArgumentException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }
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)); } }
public void DeleteuserMessage(int messageId) { var message = GetUserMessageByMessageId(messageId); if (message == null) { throw new MessageNotFoundException(MessagingConstants.MessageNotFoundInfo(messageId)); } //remove the message _context.UserMessages .Remove(message); // confirm changes _context.SaveChanges(); }
public IEnumerable <UserMessages> GetUserMessagesByAdvertismentId(int advertId, string currentUserId) { try { return(_repository.GetUserMessagesByAdvertismentId(advertId, currentUserId)); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageGetErrorGeneral()); throw; } }
public UserMessages GetUserMessageByMessageId(int messageId) { try { return(_repository.GetUserMessageByMessageId(messageId)); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageGetError(messageId)); throw; } }
public void UpdateMessageReadStatus(int messageId, bool newReadStatus) { try { _repository.UpdateMessageReadStatus(messageId, newReadStatus); } catch (MessageNotFoundException ex) { Log.Error(ex, MessagingConstants.MessageNotFoundInfo(messageId)); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageSaveError(messageId)); throw; } }
public IEnumerable <UserMessages> GetUserMessagesByFromUserToUser(string fromUserId, string toUserId) { try { return(_repository.GetUserMessagesByFromUserToUser(fromUserId, toUserId)); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageGetErrorGeneral()); throw; } }
public async Task <IEnumerable <UserContactInfo> > GetAvailableContactsForOwner(int advertId, string ownerId) { try { List <UserContactInfo> usersContactsInfo = new List <UserContactInfo>(); List <UserMessages> result = _repository.GetUserMessagesByAdvertismentId(advertId, ownerId) .Where(m => m.FromUserId != ownerId) .GroupBy(m => new { m.FromUserId, m.ToUserId }) .Select(s => s.LastOrDefault()) .OrderByDescending(o => o.DateSent) .ToList(); // get the messaging history between owner and target people foreach (var userMessage in result) { string contactUserId = userMessage.FromUserId != ownerId ? userMessage.FromUserId : userMessage.ToUserId; usersContactsInfo.Add(new UserContactInfo { UserId = contactUserId, LastMessage = userMessage.MessageContent, UserName = await _userService.GetUserNameFromUserIdAsync(contactUserId) }); } return(usersContactsInfo); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.ContactsGetErrorGeneral()); throw; } }
public IEnumerable <UserMessages> GetAdvertMessagesBetweenOwnerAndUser(int advertId, string ownerId, string targetUserId) { try { return(_repository.GetAdvertUserMessagesBetweenOwnerAndUser(advertId, ownerId, targetUserId)); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.ContactsGetErrorGeneral()); throw; } }
public void UpdateMessageReadStatus(int messageId, bool newReadStatus) { var message = GetUserMessageByMessageId(messageId); if (message == null) { throw new MessageNotFoundException(MessagingConstants.MessageNotFoundInfo(messageId)); } //Update flag _context.UserMessages .Where(a => a.MessageId == messageId) .FirstOrDefault() .Read = newReadStatus; // save changes _context.SaveChanges(); }
public IEnumerable <UserMessages> GetUserMessagesByFromUserToUserAndDateSentAndRead(string fromUserId, string toUserId, DateTime dateSent, bool readStatus) { try { return(_repository.GetUserMessagesByFromUserToUserAndDateSentAndRead(fromUserId, toUserId, dateSent, readStatus)); } catch (ArgumentNullException ex) { Log.Error(ex, MessagingConstants.ARGUMENT_NULL_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageGetErrorGeneral()); throw; } }
public void DeleteUserMessage(int messageId) { try { _repository.DeleteuserMessage(messageId); } catch (MessageNotFoundException ex) { Log.Error(ex, MessagingConstants.MessageNotFoundInfo(messageId)); throw; } catch (DbUpdateException ex) { Log.Error(ex, MessagingConstants.CANNOT_DELETE_MESSAGE); } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageDeleteError(messageId)); throw; } }
public int SaveUserMessage(UserMessages message) { try { // set additional 'server' properties message.DateSent = DateTime.UtcNow; message.Deleted = false; message.Read = false; return(_repository.SaveUserMessage(message)); } catch (DbUpdateException ex) { Log.Error(ex, MessagingConstants.CANNOT_SAVE_MESSAGE); throw; } catch (Exception ex) { Log.Error(ex, MessagingConstants.MessageSaveError(message.MessageId)); throw; } }