Ejemplo n.º 1
0
        public void MarkAsSolution(EntityIdViewModel markAsSolutionBadgeViewModel)
        {
            try
            {
                var post = _postService.Get(markAsSolutionBadgeViewModel.Id);

                bool databaseUpdateNeeded;

                if (post.User != post.Topic.User)
                {
                    databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User) | _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.Topic.User);
                }
                else
                {
                    databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User);
                }

                if (databaseUpdateNeeded)
                {
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }
        }
Ejemplo n.º 2
0
        public void VoteDownPost(EntityIdViewModel voteUpBadgeViewModel)
        {
            try
            {
                var loggedOnUser            = User.GetMembershipUser(MembershipService, false);
                var databaseUpdateNeededOne = _badgeService.ProcessBadge(BadgeType.VoteDown, loggedOnUser);
                if (databaseUpdateNeededOne)
                {
                    Context.SaveChanges();
                }

                var post = _postService.Get(voteUpBadgeViewModel.Id);
                var databaseUpdateNeededTwo = _badgeService.ProcessBadge(BadgeType.VoteDown, post.User);

                if (databaseUpdateNeededTwo)
                {
                    Context.SaveChanges();
                }

                if (databaseUpdateNeededOne || databaseUpdateNeededTwo)
                {
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }
        }
Ejemplo n.º 3
0
        public virtual async Task <ActionResult> MarkAsSolution(EntityIdViewModel markAsSolutionBadgeViewModel)
        {
            try
            {
                var post = _postService.Get(markAsSolutionBadgeViewModel.Id);

                bool databaseUpdateNeeded;

                if (post.User != post.Topic.User)
                {
                    databaseUpdateNeeded = await _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User) | await _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.Topic.User);
                }
                else
                {
                    databaseUpdateNeeded = await _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User);
                }

                if (databaseUpdateNeeded)
                {
                    await Context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }

            // TODO - Should be returning something meaningful!
            return(Content(string.Empty));
        }
Ejemplo n.º 4
0
        public virtual async Task <ActionResult> VoteDownPost(EntityIdViewModel voteUpBadgeViewModel)
        {
            try
            {
                var loggedOnUser            = User.GetMembershipUser(MembershipService, false);
                var databaseUpdateNeededOne = await _badgeService.ProcessBadge(BadgeType.VoteDown, loggedOnUser);

                if (databaseUpdateNeededOne)
                {
                    await Context.SaveChangesAsync();
                }

                var post = _postService.Get(voteUpBadgeViewModel.Id);
                var databaseUpdateNeededTwo = await _badgeService.ProcessBadge(BadgeType.VoteDown, post.User);

                if (databaseUpdateNeededTwo)
                {
                    await Context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }

            // TODO - Should be returning something meaningful!
            return(Content(string.Empty));
        }
Ejemplo n.º 5
0
        public virtual JsonResult FavouritePost(EntityIdViewModel viewModel)
        {
            var returnValue = new FavouriteJsonReturnModel();

            User.GetMembershipUser(MembershipService);
            if (Request.IsAjaxRequest() && LoggedOnReadOnlyUser != null)
            {
                try
                {
                    var post  = _postService.Get(viewModel.Id);
                    var topic = _topicService.Get(post.Topic.Id);

                    // See if this is a user adding or removing the favourite
                    Guid?user;
                    if (LoggedOnReadOnlyUser == null)
                    {
                        user = null;
                    }
                    else
                    {
                        user = LoggedOnReadOnlyUser.Id;
                    }
                    ;
                    var loggedOnUser      = MembershipService.GetUser(user);
                    var existingFavourite = _favouriteService.GetByMemberAndPost(loggedOnUser.Id, post.Id);
                    if (existingFavourite != null)
                    {
                        _favouriteService.Delete(existingFavourite);
                        returnValue.Message = LocalizationService.GetResourceString("Post.Favourite");
                    }
                    else
                    {
                        var favourite = new Favourite
                        {
                            DateCreated = DateTime.UtcNow,
                            Member      = loggedOnUser,
                            Post        = post,
                            Topic       = topic
                        };
                        _favouriteService.Add(favourite);
                        returnValue.Message = LocalizationService.GetResourceString("Post.Favourited");
                        returnValue.Id      = favourite.Id;
                    }

                    Context.SaveChanges();
                    return(Json(returnValue, JsonRequestBehavior.DenyGet));
                }
                catch (Exception ex)
                {
                    Context.RollBack();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.Generic"));
                }
            }
            return(Json(returnValue));
        }
Ejemplo n.º 6
0
 public PartialViewResult GetVoters(EntityIdViewModel voteUpViewModel)
 {
     if (Request.IsAjaxRequest())
     {
         var post          = _postService.Get(voteUpViewModel.Id);
         var positiveVotes = post.Votes.Where(x => x.Amount > 0);
         var viewModel     = new ShowVotersViewModel {
             Votes = positiveVotes.ToList()
         };
         return(PartialView(viewModel));
     }
     return(null);
 }
Ejemplo n.º 7
0
 public PartialViewResult GetVotes(EntityIdViewModel voteUpViewModel)
 {
     if (Request.IsAjaxRequest())
     {
         var post          = _postService.Get(voteUpViewModel.Id);
         var positiveVotes = post.Votes.Count(x => x.Amount > 0);
         var negativeVotes = post.Votes.Count(x => x.Amount <= 0);
         var viewModel     = new ShowVotesViewModel {
             DownVotes = negativeVotes, UpVotes = positiveVotes
         };
         return(PartialView(viewModel));
     }
     return(null);
 }
Ejemplo n.º 8
0
        public virtual async Task <ActionResult> MarkAsSolution(EntityIdViewModel markAsSolutionViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);

                // 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(markAsSolutionViewModel.Id);

                // 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 = await _topicService.SolveTopic(topic, post, marker, solutionWriter);

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

            // TODO - Should be returning something more meaningful
            return(Content(string.Empty));
        }
Ejemplo n.º 9
0
        public void Time(EntityIdViewModel timeBadgeViewModel)
        {
            try
            {
                var user = MembershipService.GetUser(timeBadgeViewModel.Id);
                var databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.Time, user);

                if (databaseUpdateNeeded)
                {
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }
        }
Ejemplo n.º 10
0
        public virtual async Task <ActionResult> VoteUpPost(EntityIdViewModel voteUpViewModel)
        {
            if (Request.IsAjaxRequest())
            {
                var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);

                // 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(voteUpViewModel.Id);

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

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

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

                try
                {
                    Context.SaveChanges();
                }

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

            // TODO - need to return something more meaningful
            return(Content(string.Empty));
        }
Ejemplo n.º 11
0
        public void Favourite(EntityIdViewModel favouriteViewModel)
        {
            try
            {
                var favourite            = _favouriteService.Get(favouriteViewModel.Id);
                var databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.Favourite, favourite.Member) |
                                           _badgeService.ProcessBadge(BadgeType.Favourite, favourite.Post.User);

                if (databaseUpdateNeeded)
                {
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }
        }
Ejemplo n.º 12
0
        public virtual async Task <ActionResult> Time(EntityIdViewModel timeBadgeViewModel)
        {
            try
            {
                var user = MembershipService.GetUser(timeBadgeViewModel.Id);
                var databaseUpdateNeeded = await _badgeService.ProcessBadge(BadgeType.Time, user);

                if (databaseUpdateNeeded)
                {
                    await Context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }

            // TODO - Should be returning something meaningful!
            return(Content(string.Empty));
        }
Ejemplo n.º 13
0
        public virtual async Task <ActionResult> Favourite(EntityIdViewModel favouriteViewModel)
        {
            try
            {
                var favourite            = _favouriteService.Get(favouriteViewModel.Id);
                var databaseUpdateNeeded = await _badgeService.ProcessBadge(BadgeType.Favourite, favourite.Member) |
                                           await _badgeService.ProcessBadge(BadgeType.Favourite, favourite.Post.User);

                if (databaseUpdateNeeded)
                {
                    await Context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
            }

            // TODO - Should be returning something meaningful!
            return(Content(string.Empty));
        }
Ejemplo n.º 14
0
        public virtual void BlockOrUnBlock(EntityIdViewModel viewModel)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    // Get a db user
                    var loggedOnUser = MembershipService.GetUser(User.Identity.Name, true);

                    // Other member
                    MembershipUser otherMember = MembershipService.GetUser(viewModel.Id);

                    var block = loggedOnUser.BlockedUsers.FirstOrDefault(x => x.Blocked.Id == otherMember.Id);
                    if (block != null)
                    {
                        var getBlock = _blockService.Get(block.Id);
                        _blockService.Delete(getBlock);
                    }
                    else
                    {
                        loggedOnUser.BlockedUsers.Add(new Block
                        {
                            Blocked = otherMember,
                            Blocker = loggedOnUser,
                            Date    = DateTime.Now
                        });
                    }

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