Exemple #1
0
        public ActionResult MarkAsSolution(MarkAsSolutionViewModel markAsSolutionViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                // Quick check to see if user is locked out, when logged in
                if (CurrentMember.IsLockedOut | !CurrentMember.IsApproved)
                {
                    ServiceFactory.MemberService.LogOff();
                    throw new Exception(Lang("Errors.NoAccess"));
                }


                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    // Firstly get the post
                    var post = ServiceFactory.PostService.Get(markAsSolutionViewModel.Post);

                    // Check the member marking owns the topic
                    if (CurrentMember.Id == post.Topic.MemberId)
                    {
                        // Person who created the solution post
                        var solutionWriter = ServiceFactory.MemberService.Get(post.MemberId);

                        // Get the post topic
                        var topic = post.Topic;

                        // Now get the current user
                        var marker = CurrentMember;
                        try
                        {
                            var solved = ServiceFactory.TopicService.SolveTopic(topic, post, marker, solutionWriter);

                            if (solved)
                            {
                                unitOfWork.Commit();
                                return(Content(string.Format("{0} {1}", "<span class=\"glyphicon glyphicon-ok\"></span>", Lang("Post.Solution"))));
                            }
                        }
                        catch (Exception ex)
                        {
                            unitOfWork.Rollback();
                            LogError(ex);
                            throw new Exception(Lang("Errors.GenericMessage"));
                        }
                    }
                    else
                    {
                        throw new Exception(Lang("Errors.Generic"));
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public void MarkAsSolution(MarkAsSolutionViewModel markAsSolutionViewModel)
        {
            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"));
                }

                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    // Get a db user
                    var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

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

                    // Person who created the solution post
                    var solutionWriter = post.User;

                    // Get the post topic
                    var topic = post.Topic;

                    // Now get the current user
                    var marker = loggedOnUser;
                    try
                    {
                        var solved = _topicService.SolveTopic(topic, post, marker, solutionWriter);

                        if (solved)
                        {
                            unitOfWork.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                        throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                    }
                }
            }
        }
Exemple #3
0
        public void MarkAsSolution(MarkAsSolutionViewModel markAsSolutionViewModel)
        {
            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"));
                }

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

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

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

                    // Person who created the solution post
                    var solutionWriter = post.User;

                    // Get the post topic
                    var topic = post.Topic;

                    // Now get the current user
                    var marker = loggedOnUser;
                    try
                    {
                        var solved = _topicService.SolveTopic(topic, post, marker, solutionWriter);

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

                }
            }
        }