public IActionResult NewIdea(Guid sessionId) { OperationResultVo <BrainstormSessionViewModel> sessionResult; if (sessionId == Guid.Empty) { sessionResult = brainstormAppService.GetMainSession(); } else { sessionResult = brainstormAppService.GetSession(sessionId); } if (sessionResult.Success) { sessionId = sessionResult.Value.Id; ViewData["Session"] = sessionResult.Value; } BrainstormIdeaViewModel vm = new BrainstormIdeaViewModel { SessionId = sessionId }; if (Request.IsAjaxRequest()) { return(PartialView("_CreateEdit", vm)); } else { return(View("_CreateEdit", vm)); } }
public IActionResult Details(Guid id) { OperationResultVo <BrainstormIdeaViewModel> op = brainstormAppService.GetById(CurrentUserId, id); BrainstormIdeaViewModel vm = op.Value; SetAuthorDetails(vm); return(View("_Details", vm)); }
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)); } }
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)); } }
public IActionResult Save(BrainstormIdeaViewModel vm) { try { bool isNew = vm.Id == Guid.Empty; vm.UserId = CurrentUserId; brainstormAppService.Save(CurrentUserId, vm); string url = Url.Action("Index", "Brainstorm", new { area = string.Empty, id = vm.SessionId.ToString() }); if (isNew) { NotificationSender.SendTeamNotificationAsync($"New idea posted: {vm.Title}"); } return(Json(new OperationResultRedirectVo(url))); } catch (Exception ex) { return(Json(new OperationResultVo(ex.Message))); } }