Example #1
0
    /// <summary>
    /// Get from database all conversation related of the user
    /// </summary>
    private void BindData()
    {
        var listMessagesFrom       = MessageComponent.GetMessagesFrom(UserInfo.UserID).ToList();
        var usersTo                = (from s in listMessagesFrom select s.ToUserId).Distinct();
        var listMessagesTo         = MessageComponent.GetMessagesTo(UserInfo.UserID).ToList();
        var usersFrom              = (from s in listMessagesTo select s.FromUserId).Distinct();
        var ListUsersConversations = usersFrom.Concat(usersTo).Distinct();
        List <UserProperty> list   = new List <UserProperty>();

        foreach (int id in ListUsersConversations)
        {
            UserPropertyComponent userProperty = new UserPropertyComponent(id);
            list.Add(userProperty.UserProperty);
        }
        if (list.Count <= 0)
        {
            noMessageContainer.Visible = true;
        }
        else
        {
            noMessageContainer.Visible = false;
        }

        rpConversations.DataSource = list;
        rpConversations.DataBind();
    }
Example #2
0
        public List <MessageModel> GetListTo(int rows = 10, int page = 0)
        {
            try
            {
                var portal      = PortalController.GetCurrentPortalSettings();
                var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

                if (currentUser.IsInRole("Registered Users"))
                {
                    var result     = MessageComponent.GetMessagesTo(currentUser.UserID).OrderByDescending(p => p.DateCreated);
                    var totalCount = result.Count();
                    var totalPages = (int)Math.Ceiling((double)totalCount / rows);
                    var prevLink   = page > 0 ? string.Format("/messages/GetListTo?rows={0}&page={1}", rows, page - 1) : "";
                    var nextLink   = page < totalPages - 1 ? string.Format("/messages/GetListTo?rows={0}&page={1}", rows, page + 1) : "";


                    List <MessageModel> messagesModel = new List <MessageModel>();

                    foreach (var resultTmp in result.Skip(rows * page).Take(rows).ToList())
                    {
                        messagesModel.Add(new MessageModel()
                        {
                            MessageId   = resultTmp.MessageId,
                            Message     = resultTmp.Message1,
                            FromUserId  = Convert.ToInt32(resultTmp.FromUserId),
                            ToUserId    = Convert.ToInt32(resultTmp.ToUserId),
                            CreatedDate = Convert.ToDateTime(resultTmp.DateCreated),
                            DateRead    = Convert.ToDateTime(resultTmp.DateRead)
                        });
                    }

                    var paginationHeader = new
                    {
                        TotalCount   = totalCount,
                        TotalPages   = totalPages,
                        PrevPageLink = prevLink,
                        NextPageLink = nextLink
                    };

                    System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination",
                                                                        Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));

                    return(messagesModel);
                }
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            catch (HttpResponseException e)
            {
                throw e;
            }
            catch (Exception ee)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ee);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }