public Comment CreateComment(string caption, Guidable target)
 {
     var comment = _context.Blocks.Add(new Comment()
     {
         Id = Guid.NewGuid(),
         Caption = caption,
         Target = target
     });
     SaveChanges();
     return comment as Comment;
 }
        public CreateCommentDlgViewModel(IParticlesManager particlesManager, IBlockManager blockManager,
            ICommentManager commentManager, IEventAggregator eventAggregator)
        {
            _particlesManager = particlesManager;
            _blockManager = blockManager;
            _commentManager = commentManager;
            _eventAggregator = eventAggregator;
            AddParticleVm = new AddParticleViewViewModel(particlesManager);

            SelectBlockCommand = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(typeof (Guidable));
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _myGuidable = _blockManager.GetGuidableById(dlg.Id.Value);
                    OkCommand.RaiseCanExecuteChanged();
                    if (_myGuidable is Material)
                        GuidableCaption = (_myGuidable as Material).Name;
                    else if (_myGuidable is Block)
                        GuidableCaption = (_myGuidable as Block).Caption;
                }
            });

            OkCommand = new DelegateCommand<Window>((wnd) =>
            {
                var comment = _commentManager.CreateComment(Caption, _myGuidable);

                if (AddParticleVm.AddParticle)
                    if (AddParticleVm.UseNewParticle)
                    {
                        var particle = _particlesManager.CreateParticle(AddParticleVm.NewParticle.Material,
                            AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                        _blockManager.AddParticleToBlock(comment, particle);
                        ParticleId = particle.Id;
                    }
                    else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                    {
                        var particle = _particlesManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                        _blockManager.AddParticleToBlock(comment, particle);
                        ParticleId = particle.Id;
                    }

                _eventAggregator.GetEvent<BlockAddedEvent>().Publish(comment.Id);
                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => !String.IsNullOrWhiteSpace(Caption) && _myGuidable != null);
        }
 public Comment CreateComment(string caption, Guidable target)
 {
     return _dbInterop.CreateComment(caption, target);
 }