Exemplo n.º 1
0
        public OperationResultVo Comment(CommentViewModel vm)
        {
            try
            {
                BrainstormIdea    idea  = brainstormDomainService.GetIdea(vm.UserContentId);
                BrainstormComment model = new BrainstormComment
                {
                    UserId        = vm.UserId,
                    IdeaId        = vm.UserContentId,
                    SessionId     = idea.SessionId,
                    Text          = vm.Text,
                    AuthorName    = vm.AuthorName,
                    AuthorPicture = vm.AuthorPicture
                };

                brainstormDomainService.AddComment(model);

                unitOfWork.Commit();

                return(new OperationResultVo <Guid>(model.Id));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <Guid>(ex.Message));
            }
        }
Exemplo n.º 2
0
        public async Task AddIdea(BrainstormIdea model)
        {
            if (model.Status == 0)
            {
                model.Status = BrainstormIdeaStatus.Proposed;
            }

            await GetCollection <BrainstormIdea>().InsertOneAsync(model);
        }
Exemplo n.º 3
0
        public OperationResultVo <BrainstormIdeaViewModel> GetById(Guid currentUserId, Guid id)
        {
            try
            {
                BrainstormIdea idea          = brainstormDomainService.GetIdea(id);
                Guid           sessionUserId = brainstormDomainService.GetUserId(idea.SessionId);

                BrainstormIdeaViewModel vm = mapper.Map <BrainstormIdeaViewModel>(idea);

                vm.UserContentType = UserContentType.Idea;
                vm.VoteCount       = idea.Votes.Count;
                vm.Score           = idea.Votes.Sum(x => (int)x.VoteValue);
                vm.CurrentUserVote = idea.Votes.FirstOrDefault(x => x.UserId == currentUserId)?.VoteValue ?? VoteValue.Neutral;

                vm.CommentCount = idea.Comments.Count;

                IQueryable <CommentViewModel> commentsVm = idea.Comments.AsQueryable().ProjectTo <CommentViewModel>(mapper.ConfigurationProvider);

                vm.Comments = commentsVm.OrderBy(x => x.CreateDate).ToList();

                foreach (CommentViewModel comment in vm.Comments)
                {
                    UserProfile commenterProfile = GetCachedProfileByUserId(comment.UserId);
                    if (commenterProfile == null)
                    {
                        comment.AuthorName = Constants.UnknownSoul;
                    }
                    else
                    {
                        comment.AuthorName = commenterProfile.Name;
                    }

                    comment.AuthorPicture = UrlFormatter.ProfileImage(comment.UserId);
                    comment.Text          = string.IsNullOrWhiteSpace(comment.Text) ? Constants.SoundOfSilence : comment.Text;
                }

                vm.Permissions.CanEdit = currentUserId == sessionUserId;

                return(new OperationResultVo <BrainstormIdeaViewModel>(vm));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <BrainstormIdeaViewModel>(ex.Message));
            }
        }
Exemplo n.º 4
0
        public OperationResultVo Vote(Guid userId, Guid ideaId, VoteValue vote)
        {
            try
            {
                BrainstormVote model;
                BrainstormIdea idea = brainstormDomainService.GetIdea(ideaId);

                BrainstormVote existing = idea.Votes.FirstOrDefault(x => x.UserId == userId);
                if (existing != null)
                {
                    model           = existing;
                    model.VoteValue = vote;
                }
                else
                {
                    model = new BrainstormVote
                    {
                        UserId    = userId,
                        IdeaId    = ideaId,
                        SessionId = idea.SessionId,
                        VoteValue = vote
                    };
                }

                if (model.Id == Guid.Empty)
                {
                    brainstormDomainService.AddVote(model);
                }
                else
                {
                    brainstormDomainService.UpdateVote(model);
                }

                unitOfWork.Commit();

                return(new OperationResultVo <Guid>(model.Id));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <Guid>(ex.Message));
            }
        }
Exemplo n.º 5
0
        public OperationResultVo <Guid> Save(Guid currentUserId, BrainstormIdeaViewModel viewModel)
        {
            try
            {
                BrainstormSession session = brainstormDomainService.GetById(viewModel.SessionId);

                BrainstormIdea model;

                BrainstormIdea existing = brainstormDomainService.GetIdea(viewModel.Id);
                if (existing != null)
                {
                    model = mapper.Map(viewModel, existing);
                }
                else
                {
                    model = mapper.Map <BrainstormIdea>(viewModel);
                }

                model.SessionId = session.Id;

                if (model.Id == Guid.Empty)
                {
                    brainstormDomainService.AddIdea(model);
                }
                else
                {
                    brainstormDomainService.UpdateIdea(model);
                }

                gamificationDomainService.ProcessAction(viewModel.UserId, PlatformAction.IdeaSuggested);

                unitOfWork.Commit();

                return(new OperationResultVo <Guid>(model.Id));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <Guid>(ex.Message));
            }
        }
Exemplo n.º 6
0
        public OperationResultVo ChangeStatus(Guid currentUserId, Guid ideaId, BrainstormIdeaStatus selectedStatus)
        {
            try
            {
                BrainstormIdea idea = brainstormDomainService.GetIdea(ideaId);

                if (idea == null)
                {
                    return(new OperationResultVo("Idea not found!"));
                }

                idea.Status = selectedStatus;

                brainstormDomainService.UpdateIdea(idea);

                unitOfWork.Commit();

                return(new OperationResultVo(true));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo(ex.Message));
            }
        }
 public void UpdateIdea(BrainstormIdea idea)
 {
     repository.UpdateIdea(idea);
 }
 public void AddIdea(BrainstormIdea model)
 {
     repository.AddIdea(model);
 }
Exemplo n.º 9
0
        public async Task <bool> UpdateIdea(BrainstormIdea idea)
        {
            ReplaceOneResult result = await GetCollection <BrainstormIdea>().ReplaceOneAsync(x => x.Id == idea.Id, idea);

            return(result.IsAcknowledged && result.ModifiedCount > 0);
        }
Exemplo n.º 10
0
        public async Task <BrainstormIdea> GetIdea(Guid ideaId)
        {
            BrainstormIdea idea = await GetCollection <BrainstormIdea>().FindSync(x => x.Id == ideaId).FirstOrDefaultAsync();

            return(idea);
        }