aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs
blob: 6f37f4788fdc0afc3b282b9e37e4ec8717e03288 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.BL.Entities
{
    public partial class Segment
    {
        public override void Save(ObservablesContext context)
        {
            for (int i = 0; i < BrushStops.Count; i++)
            {
                BrushStops[i].StopIndex = i;
            }

            base.Save(context);
        }

        protected override void RaisePropertyChanged(string propName)
        {
            base.RaisePropertyChanged(propName);

            if (propName == nameof(Length))
            {
                BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged());
            }
        }

        private TimeSpan _remainingTime;
        [NotMapped]
        [JsonIgnore]
        public TimeSpan RemainingTime
        {
            get { return _remainingTime; }
            set { _remainingTime = value; RaisePropertyChangedAuto(); }
        }

        private bool _started;
        [NotMapped]
        [JsonIgnore]
        public bool Started
        {
            get { return _started; }
            set { _started = value; RaisePropertyChangedAuto(); }
        }

        private bool _completed;
        [NotMapped]
        [JsonIgnore]
        public bool Completed
        {
            get { return _completed; }
            set { _completed = value; RaisePropertyChangedAuto(); }
        }

        public override Segment Clone()
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone()).ToObservableCollection();

            return cloned;
        }

        public Segment Clone(Job job)
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone(cloned)).ToObservableCollection();

            cloned.Job = job;
            cloned.JobGuid = job.Guid;

            return cloned;
        }

        public override void DefferedDelete(ObservablesContext context)
        {
            BrushStops.ToList().ForEach(x => x.DefferedDelete(context));
            BrushStops.Clear();
            base.DefferedDelete(context);
        }
    }
}