Ejemplo n.º 1
0
        public IdeationDto GetIdeation(int ideationId, string userId)
        {
            try
            {
                var ideation = _ideationManager.GetIdeation(ideationId);
                if (ideation == null)
                {
                    throw new ArgumentException("Ideation not found", "ideationId");
                }

                var dto = _mapper.Map <IdeationDto>(ideation);

                var vote = _userManager.GetVoteForIdeation(ideationId, userId);
                if (vote != null)
                {
                    dto.UserVoteValue = vote.Value;
                }

                return(dto);
            }
            catch (Exception e)
            {
                throw new Exception($"Something went wrong in getting the ideation: {e.Message}.");
            }
        }
        public IActionResult Details(int id)
        {
            string userId = null;

            if (_signInManager.IsSignedIn(User))
            {
                userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            }
            Ideation ideation = _ideationManager.GetIdeation(id);
            var      ideas    = _ideasHelper.GetIdeas(userId, ideation.IdeationId);

            Dictionary <int, SAVotes> ideaVotes = new Dictionary <int, SAVotes>();

            foreach (var idea in ideas)
            {
                var anVotes  = 0;
                var veVotes  = 0;
                var usVotes  = 0;
                var realIdea = _ideationManager.GetIdea(idea.IdeaId);
                foreach (var vote in realIdea.Votes)
                {
                    if (vote.User != null)
                    {
                        usVotes += vote.Value;
                    }
                    else if (vote.Email != null)
                    {
                        veVotes += vote.Value;
                    }
                    else
                    {
                        anVotes += vote.Value;
                    }
                }
                ideaVotes.Add(realIdea.IdeaId, new SAVotes()
                {
                    anVotes = anVotes,
                    veVotes = veVotes,
                    usVotes = usVotes
                });
            }

            var model = new IdeationUserVote
            {
                ideas     = ideas,
                ideation  = ideation,
                ideaVotes = ideaVotes
            };

            return(View(model));
        }