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; } }