public void Paste()
        {
            var effectedRows = new SeatBox[_occupationClipboard.Length + 1];

            effectedRows[effectedRows.Length - 1] = SelectedSeat;
            Action applyChanges = () => { };

            for (var i = 0; i < _occupationClipboard.Length; i++)
            {
                var index      = i;
                var occupation = _occupationClipboard[i];
                _seatBoxes[occupation.Seat.Id.ToString()].SaftyInvoke <SeatBox>(o =>
                {
                    if (o.RemoveOccupation(occupation) && SelectedSeat.AddOccupation(occupation))
                    {
                        occupation.Seat = SelectedSeat.Seat;
                        applyChanges    =
                            occupation.Is <SeatArrangement>() ?
                            (() => TrySubmitChanged(false, ((SeatArrangement)occupation).Agent)) : new Action(() =>
                        {
                            _seatDispatcherModel.SubmitChanges();
                            _occupationClipboard = null;
                        });
                    }
                    effectedRows[index] = o;
                });
            }
            applyChanges.Invoke();
            Reload(effectedRows);
            OccupationsReloaded(null);
        }
        public void AssignSeat(Term shift, IWorkingAgent selectedAgent)
        {
            var affectedRows = new[] { SelectedSeat };

            if (!shift.SeatIsEmpty())
            {
                var removeDelegates = new Action(() => { });
                affectedRows = selectedAgent.Schedule.GetCoveredTermsWithAbsent(shift).Add(shift)
                               .Where(o => !o.SeatIsEmpty() && _seatBoxes.ContainsKey(o.Seat))
                               .Select(o =>
                {
                    var seatBox = (SeatBox)_seatBoxes[o.Seat];
                    foreach (var c in seatBox.Occupations.Where(c => c.If <SeatArrangement>(a => a.Source.Equals(o))))
                    {
                        var occupation   = c;
                        removeDelegates += () =>
                        {
                            seatBox.RemoveOccupation(occupation);
                            selectedAgent.Occupations.Remove(occupation);
                        };
                    }
                    return(seatBox);
                })
                               .ToArray();
                removeDelegates();

                //var originalSeat = (SeatBox)_seatBoxes[shift.Seat];
                //var seatArrangement = originalSeat.Occupations.OfType<SeatArrangement>().FirstOrDefault(o => o.Source == shift && o.TimeEquals(shift));
                //if (seatArrangement != null)
                //    originalSeat.RemoveOccupation(seatArrangement);
                //affectedRows = new[] { SelectedSeat, originalSeat };
            }

            var prv    = default(Term);
            var seatId = SelectedSeat.Id.ToString();

            shift.Seat = seatId;
            var coveredTerms = selectedAgent.Schedule.GetCoveredTermsWithAbsent(shift);

            coveredTerms.ForEach(o => o.Seat = null).Add(shift)
            .SliceOccupied((dateRange, term) =>
            {
                if (!term.IsNeedSeat)
                {
                    term.Seat = seatId;
                    prv       = term;
                    return(default(SeatArrangement));
                }

                if (prv != null && !ReferenceEquals(prv, term) && prv.Level == 0 && term.Level == 0)
                {
                    prv = null;
                }

                var source = default(Term);
                TermExt.X(prv, term, ref source);
                var instance = new SeatArrangement(selectedAgent.Profile, dateRange.Start, dateRange.End, SelectedSeat.Seat)
                {
                    Source = source
                };
                source.Seat = seatId;
                SelectedSeat.AddOccupation(instance);
                selectedAgent.Occupations.Add(instance);
                prv = term;
                return(instance);
            }, t => t.IsNeedSeat);
            //shift.SaftyInvoke<AssignmentBase>(o => { o.OccupyStatus = "C"; });
            Reload(affectedRows);
            OccupationsChanged(-1);
        }