Пример #1
0
        public void VoteDownPost(VoteDownViewModel voteDownViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                // Quick check to see if user is locked out, when logged in
                if (LoggedOnReadOnlyUser.IsLockedOut | !LoggedOnReadOnlyUser.IsApproved)
                {
                    FormsAuthentication.SignOut();
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
                }

                // Get a db user
                var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

                // Firstly get the post
                var post = _postService.Get(voteDownViewModel.Post);

                // Now get the current user
                var voter = loggedOnUser;

                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    // Also get the user that wrote the post
                    var postWriter = post.User;

                    // Mark the post up or down
                    MarkPostUpOrDown(post, postWriter, voter, PostType.Negative);

                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                        throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                    }
                }
            }
        }
Пример #2
0
        public void VoteDownPost(VoteDownViewModel voteDownViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                // Quick check to see if user is locked out, when logged in
                if (LoggedOnReadOnlyUser.IsLockedOut | !LoggedOnReadOnlyUser.IsApproved)
                {
                    FormsAuthentication.SignOut();
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
                }

                // Get a db user
                var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

                // Firstly get the post
                var post = _postService.Get(voteDownViewModel.Post);

                // Now get the current user
                var voter = loggedOnUser;

                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {

                    // Also get the user that wrote the post
                    var postWriter = post.User;

                    // Mark the post up or down
                    MarkPostUpOrDown(post, postWriter, voter, PostType.Negative);

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

                }
            }
        }