public async Task <ActionResult> View(int id)
        {
            var user = _userRetrievalShim.GetUser();

            if (user == null)
            {
                return(StatusCode(403));
            }
            var pm = await _privateMessageService.Get(id);

            if (await _privateMessageService.IsUserInPM(user, pm) == false)
            {
                return(StatusCode(403));
            }
            var posts = await _privateMessageService.GetPosts(pm);

            var model = new PrivateMessageView
            {
                PrivateMessage = pm,
                Posts          = posts
            };
            await _privateMessageService.MarkPMRead(user, pm);

            return(View(model));
        }
        public ActionResult Create(Guid?id, Guid?to)
        {
            // Check if private messages are enabled
            if (!SettingsService.GetSettings().EnablePrivateMessages || LoggedOnUser.DisablePrivateMessages == true)
            {
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.GenericMessage")));
            }

            // Check flood control
            var lastMessage = _privateMessageService.GetLastSentPrivateMessage(LoggedOnUser.Id);

            if (lastMessage != null && DateUtils.TimeDifferenceInMinutes(DateTime.UtcNow, lastMessage.DateSent) < SettingsService.GetSettings().PrivateMessageFloodControl)
            {
                return(ErrorToInbox(LocalizationService.GetResourceString("PM.SendingToQuickly")));
            }

            // Check outbox size of logged in user
            var senderCount = _privateMessageService.GetAllSentByUser(LoggedOnUser.Id).Count;

            if (senderCount > SettingsService.GetSettings().MaxPrivateMessagesPerMember)
            {
                return(ErrorToInbox(LocalizationService.GetResourceString("PM.SentItemsOverCapcity")));
            }
            if (senderCount > (SettingsService.GetSettings().MaxPrivateMessagesPerMember - SiteConstants.PrivateMessageWarningAmountLessThanAllowedSize))
            {
                // Send user a warning they are about to exceed
                var sb = new StringBuilder();
                sb.AppendFormat("<p>{0}</p>", LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeBody"));
                var email = new Email
                {
                    EmailFrom = SettingsService.GetSettings().AdminEmailAddress,
                    EmailTo   = LoggedOnUser.Email,
                    NameTo    = LoggedOnUser.UserName,
                    Subject   = LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeSubject")
                };
                email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString());
                _emailService.SendMail(email);
            }

            var viewModel = new CreatePrivateMessageViewModel();

            // add the username to the to box if available
            if (to != null)
            {
                var userTo = MembershipService.GetUser((Guid)to);
                viewModel.UserToUsername = userTo.UserName;
            }

            // See if this is a reply or not
            if (id != null)
            {
                var previousMessage = _privateMessageService.Get((Guid)id);
                // Its a reply, get the details
                viewModel.UserToUsername  = previousMessage.UserFrom.UserName;
                viewModel.Subject         = previousMessage.Subject;
                viewModel.PreviousMessage = previousMessage.Message;
            }
            return(View(viewModel));
        }
        public ActionResult Delete(DeletePrivateMessageViewModel deletePrivateMessageViewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                if (Request.IsAjaxRequest())
                {
                    var privateMessage = _privateMessageService.Get(deletePrivateMessageViewModel.Id);
                    if (privateMessage.UserTo.Id == LoggedOnReadOnlyUser.Id | privateMessage.UserFrom.Id == LoggedOnReadOnlyUser.Id)
                    {
                        _privateMessageService.DeleteMessage(privateMessage);
                    }
                    else
                    {
                        throw new Exception(LocalizationService.GetResourceString("Errors.NoPermission"));
                    }
                }

                try
                {
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }

            return(null);
        }
        public ActionResult Delete(DeletePrivateMessageViewModel deletePrivateMessageViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);
                var privateMessage       = _privateMessageService.Get(deletePrivateMessageViewModel.Id);
                if ((privateMessage.UserTo.Id == loggedOnReadOnlyUser.Id) |
                    (privateMessage.UserFrom.Id == loggedOnReadOnlyUser.Id))
                {
                    _privateMessageService.DeleteMessage(privateMessage);
                }
                else
                {
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoPermission"));
                }
            }

            try
            {
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }


            return(null);
        }
        public ActionResult Create(Guid?id, Guid?to)
        {
            // Check if private messages are enabled
            if (!SettingsService.GetSettings().EnablePrivateMessages || LoggedOnUser.DisablePrivateMessages == true)
            {
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.GenericMessage")));
            }

            // Check flood control
            var lastMessage = _privateMessageService.GetLastSentPrivateMessage(LoggedOnUser.Id);

            if (lastMessage != null && DateUtils.TimeDifferenceInMinutes(DateTime.UtcNow, lastMessage.DateSent) < SettingsService.GetSettings().PrivateMessageFloodControl)
            {
                return(ErrorToInbox(LocalizationService.GetResourceString("PM.SendingToQuickly")));
            }

            // Check outbox size
            var senderCount = _privateMessageService.GetAllSentByUser(LoggedOnUser.Id).Count;

            if (senderCount > SettingsService.GetSettings().MaxPrivateMessagesPerMember)
            {
                return(ErrorToInbox(LocalizationService.GetResourceString("PM.SentItemsOverCapcity")));
            }

            var viewModel = new CreatePrivateMessageViewModel();

            // add the username to the to box if available
            if (to != null)
            {
                var userTo = MembershipService.GetUser((Guid)to);
                viewModel.UserToUsername = userTo.UserName;
            }

            // See if this is a reply or not
            if (id != null)
            {
                var previousMessage = _privateMessageService.Get((Guid)id);
                // Its a reply, get the details
                viewModel.UserToUsername  = previousMessage.UserFrom.UserName;
                viewModel.Subject         = previousMessage.Subject;
                viewModel.PreviousMessage = previousMessage.Message;
            }
            return(View(viewModel));
        }
        public ViewResult View(int id)
        {
            var user = this.CurrentUser();

            if (user == null)
            {
                return(this.Forbidden("Forbidden", null));
            }
            var pm = _privateMessageService.Get(id);

            if (!_privateMessageService.IsUserInPM(user, pm))
            {
                return(this.Forbidden("Forbidden", null));
            }
            var model = new PrivateMessageView
            {
                PrivateMessage = pm,
                Posts          = _privateMessageService.GetPosts(pm)
            };

            _privateMessageService.MarkPMRead(user, pm);
            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult View(int id)
        {
            var user = _userRetrievalShim.GetUser(HttpContext);

            if (user == null)
            {
                return(Forbid());
            }
            var pm = _privateMessageService.Get(id);

            if (!_privateMessageService.IsUserInPM(user, pm))
            {
                return(Forbid());
            }
            var model = new PrivateMessageView
            {
                PrivateMessage = pm,
                Posts          = _privateMessageService.GetPosts(pm)
            };

            _privateMessageService.MarkPMRead(user, pm);
            return(View(model));
        }