Esempio n. 1
0
        //public int Id { get; set; }
        //public string Name { get; set; }
        //public virtual ApplicationUser SuggestedBy { get; set; }
        //public virtual KnowledgeSession Session { get; set; }
        //public DateTime Date { get; set; }
        //public int? ParentId { get; set; }
        //public NodeType Type { get; set; }
        //public NodeStates State { get; set; }
        //public virtual ICollection<NodeStructureSuggestionVote> StructureVotes { get; set; }
        //public virtual ICollection<NodeModification> NodeModifications { get; set; }
        //public virtual ICollection<Comment> Comments { get; set; }
        public void SaveSuggestedNodes(SuggestedNodesViewModel model, string userId)
        {
            var session = _db.KnowledgeSessions.Get(model.SessionId);
            var user = _db.Users.Get(userId);

            var nodesList = Mapper.Map<List<NodeViewModel>, ICollection<SessionNode>>(model.Nodes);

            var suggestionId = _suggestionService.CreateSuggestion(userId, model.ParentId);
            foreach (var node in nodesList)
            {
                node.Date = DateTime.Now;
                node.SuggestedBy = user;
                node.Session = session;
                node.ParentId = model.ParentId;
                node.State = NodeStates.StructureSuggestion;
                node.Type = NodeType.Suggested;
                node.NodeStructureSuggestion = _db.NodeStructureSuggestions.Get(suggestionId);
                session.SessionNodes.Add(node);
                user.SessionNodes.Add(node);
            }

            var parentNode = _db.Nodes.Get(model.ParentId);

            var suggestionComplete = ParentNodeSuggestionsComplete(model.SessionId, model.ParentId);

            if (suggestionComplete)
            {
                parentNode.State = NodeStates.StructureSuggestionVote;
            }

            //var firstNode = nodes.FirstOrDefault();

            //if (firstNode != null)
            //{
            //    var result = ParentNodeSuggestionsComplete(sessionId, firstNode.Level);
            //    if (result)
            //    {
            //        session.SessionState = (int)SessionState.FirstRoundMainBoard;
            //    }
            //}

            _db.Save();
        }
        public void SaveSuggestedNodes(SuggestedNodesViewModel suggestedNodesViewModel)
        {
            _nodeService.SaveSuggestedNodes(suggestedNodesViewModel, User.Identity.GetUserId());

            //var context = GlobalHost.ConnectionManager.GetHubContext<KnowledgeSessionHub>();
            //context.Clients.All.userAddSuggestion(User.Identity.GetUserId());
        }