public ActionResult View(int from)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var userFrom = MembershipService.GetUser(from);

                if (userFrom != LoggedOnUser)
                {
                    // Mark all messages read sent to this user from the userFrom
                    var unreadMessages = LoggedOnUser.PrivateMessagesReceived.Where(x => x.UserFrom.Id == from && !x.IsRead);

                    foreach (var message in unreadMessages)
                    {
                        // Update message as read
                        message.IsRead = true;

                        // Get the sent version and update that too
                        var sentMessage = _privateMessageService.GetMatchingSentPrivateMessage(message.DateSent, message.UserFrom.Id, message.UserTo.Id);
                        if (sentMessage != null)
                        {
                            sentMessage.IsRead = true;
                        }
                    }

                    // Commit all changes
                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                    }

                    // Get all the received messages from userFrom
                    // and then get all the sent messages to userFrom

                    var allMessages = LoggedOnUser.PrivateMessagesReceived.Where(x => x.UserFrom.Id == from && x.IsSentMessage == false).ToList();
                    allMessages.AddRange(LoggedOnUser.PrivateMessagesSent.Where(x => x.UserTo.Id == from && x.IsSentMessage == true).ToList());

                    // Now order them into an order of messages

                    var viewModel = new ViewPrivateMessageViewModel
                    {
                        From            = userFrom,
                        PrivateMessages = allMessages.OrderByDescending(x => x.DateSent).ToList()
                    };

                    return(View(viewModel));
                }

                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }
        public ActionResult View(Guid id)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var message = _privateMessageService.Get(id);

                if (message.UserTo == LoggedOnUser | message.UserFrom == LoggedOnUser)
                {
                    //Mark as read if this is the receiver of the message
                    if (message.UserTo == LoggedOnUser)
                    {
                        // Update message as read
                        message.IsRead = true;

                        // Get the sent version and update that too
                        var sentMessage = _privateMessageService.GetMatchingSentPrivateMessage(message.Subject, message.DateSent, message.UserFrom.Id, message.UserTo.Id);
                        if (sentMessage != null)
                        {
                            sentMessage.IsRead = true;
                        }

                        try
                        {
                            unitOfWork.Commit();
                        }
                        catch (Exception ex)
                        {
                            unitOfWork.Rollback();
                            LoggingService.Error(ex);
                        }
                    }

                    return(View(new ViewPrivateMessageViewModel {
                        Message = message
                    }));
                }

                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }
        public ActionResult View(Guid from)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var userFrom     = MembershipService.GetUser(from);
                var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);
                if (userFrom.Id != LoggedOnReadOnlyUser.Id)
                {
                    // Mark all messages read sent to this user from the userFrom
                    var unreadMessages = loggedOnUser.PrivateMessagesReceived.Where(x => x.UserFrom.Id == from && !x.IsRead);

                    foreach (var message in unreadMessages)
                    {
                        // Update message as read
                        message.IsRead = true;

                        // Get the sent version and update that too
                        var sentMessage = _privateMessageService.GetMatchingSentPrivateMessage(message.DateSent, message.UserFrom.Id, message.UserTo.Id);
                        if (sentMessage != null)
                        {
                            sentMessage.IsRead = true;
                        }
                    }

                    // Commit all changes
                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                    }

                    // Get all the received messages from userFrom
                    // and then get all the sent messages to userFrom
                    // TODO - This is shit, and needs updating
                    //var allMessages = loggedOnUser.PrivateMessagesReceived.Where(x => x.UserFrom.Id == from && x.IsSentMessage == false).ToList();
                    //allMessages.AddRange(loggedOnUser.PrivateMessagesSent.Where(x => x.UserTo.Id == from && x.IsSentMessage == true).ToList());

                    var allMessages = _privateMessageService.GetUsersPrivateMessages(1, SiteConstants.Instance.PagingGroupSize, loggedOnUser, userFrom);

                    // Now order them into an order of messages
                    var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers);

                    var viewModel = new ViewPrivateMessageViewModel
                    {
                        From             = userFrom,
                        PrivateMessages  = allMessages,
                        FromUserIsOnline = userFrom.LastActivityDate > date,
                        IsAjaxRequest    = Request.IsAjaxRequest(),
                        IsBlocked        = loggedOnUser.BlockedUsers.Any(x => x.Blocked.Id == userFrom.Id)
                    };

                    return(View(viewModel));
                }
                var noPermissionText = LocalizationService.GetResourceString("Errors.NoPermission");
                if (Request.IsAjaxRequest())
                {
                    return(Content(noPermissionText));
                }
                return(ErrorToHomePage(noPermissionText));
            }
        }