Ejemplo n.º 1
0
 public InputSegmentEditViewModel(CoinKernelViewModel coinKernelVm, InputSegmentViewModel segment)
 {
     _old         = segment;
     segment      = new InputSegmentViewModel(segment);
     _targetGpu   = segment.TargetGpu;
     _name        = segment.Name;
     _segment     = segment.Segment;
     _description = segment.Description;
     _isDefault   = segment.IsDefault;
     this.Save    = new DelegateCommand(() => {
         if (string.IsNullOrEmpty(this.Name))
         {
             throw new ValidationException("片段名不能为空");
         }
         segment.TargetGpu   = this.TargetGpu;
         segment.Name        = this.Name;
         segment.Segment     = this.Segment;
         segment.Description = this.Description;
         segment.IsDefault   = this.IsDefault;
         bool isUpdate       = !string.IsNullOrEmpty(_old.Name);
         if (isUpdate)
         {
             var existItem = coinKernelVm.InputSegments.FirstOrDefault(a => a.Name == _old.Name && a.Segment == _old.Segment);
             if (existItem != null)
             {
                 existItem.Update(segment);
             }
         }
         else
         {
             coinKernelVm.InputSegments.Add(new InputSegment(segment));
         }
         coinKernelVm.InputSegments = coinKernelVm.InputSegments.ToList();
         VirtualRoot.Execute(new CloseWindowCommand(this.Id));
     });
 }