Example #1
0
        public async Task <UserMessageListViewModel> GetUserMessage(string userId, int skip, int limit)
        {
            try
            {
                var userMessage = new List <UserMessageBasicInformation>();
                var messages    = await _userMessageRepository.GetUserMessage(userId, skip, limit);

                var count = await _userMessageRepository.GetUserMessageCount(userId);

                if (messages == null || count == 0)
                {
                    return(new UserMessageListViewModel
                    {
                        PageCount = 0,
                        Messages = new List <UserMessageBasicInformation>()
                    });
                }
                messages.ForEach(m => userMessage.Add(new UserMessageBasicInformation
                {
                    Message     = m.Message,
                    MessageId   = m.MessageId,
                    Title       = m.Title,
                    Time        = Utilities.GetFormattedDateFromMillisecond(m.Time),
                    Status      = m.Status,
                    MessageType = m.Type,
                    ServiceId   = m.ServiceId
                }));
                return(new UserMessageListViewModel {
                    PageCount = (int)Math.Ceiling((double)count / limit),
                    Messages = userMessage
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Error getting user messages" + ex);
            }
        }