aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/RemoveSegmentsCommand.cs
blob: db44f176c70efedb4198bcbbe36de5f47bc1a86c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PPC.Jobs.Models;

namespace Tango.PPC.Jobs.UndoRedoCommands
{
    public class RemoveSegmentsCommand : IUndoRedoCommand
    {
        private JobModel _jobModel;
        private Dictionary<int,SegmentModel> _removedSegmentsDict;
        
        public RemoveSegmentsCommand(JobModel job )
        {
            _jobModel = job;
            _removedSegmentsDict = _jobModel.Segments.Select((segm, ind) => new { Index = ind, Segment = segm }).Where(x => x.Segment.IsSelected).ToDictionary(i => i.Index, i => i.Segment); ;
        }

        public void Execute()
        {
            foreach (var obj in _removedSegmentsDict)
            {
                _jobModel.Segments.Remove(obj.Value);
            }
        }

        public void UnExecute()
        {
            foreach (var obj in _removedSegmentsDict)
            {
                if (_jobModel.Segments.Count <= obj.Key)
                    _jobModel.Segments.Add(obj.Value);
                else
                {
                    _jobModel.Segments.Insert(obj.Key, obj.Value);
                }
            }

        }
    }
}