private void detach_DemandAdjustmentTransitionHistories1(DemandAdjustmentTransitionHistory entity)
		{
			this.SendPropertyChanging();
			entity.SecurityTrustee1 = null;
		}
		private void attach_DemandAdjustmentTransitionHistories1(DemandAdjustmentTransitionHistory entity)
		{
			this.SendPropertyChanging();
			entity.DemandAdjustmentState1 = this;
		}
		private void attach_DemandAdjustmentTransitionHistories(DemandAdjustmentTransitionHistory entity)
		{
			this.SendPropertyChanging();
			entity.SecurityTrustee = this;
		}
		private void detach_DemandAdjustmentTransitionHistories(DemandAdjustmentTransitionHistory entity)
		{
			this.SendPropertyChanging();
			entity.InitialState = null;
		}
 partial void DeleteDemandAdjustmentTransitionHistory(DemandAdjustmentTransitionHistory instance);
 partial void InsertDemandAdjustmentTransitionHistory(DemandAdjustmentTransitionHistory instance);
        public void UpdateDemandAdjustmentState(WorkflowState initialState, WorkflowState destinationState, WorkflowCommand command, Guid demandAdjustmentUid,
                                         Guid initiatorId, string comment)
        {
            if (!initialState.DbStateId.HasValue)
                throw new ArgumentException(
                    "Не определено соттветствие состояния Workflow отображаемому состоянию DemandAdjustment", "initialState");
            if (!destinationState.DbStateId.HasValue)
                throw new ArgumentException(
                    "Не определено соттветствие состояния Workflow отображаемому состоянию DemandAdjustment",
                    "destinationState");
            using (var scope = ReadUncommittedSupressedScope)
            {
                using (var context = CreateContext())
                {
                    var demandAdjustmentHistoryItem =
                   context.DemandAdjustmentTransitionHistories.Where(
                       p =>
                       p.DemandAdjustmentId == demandAdjustmentUid && p.InitialStateId == initialState.DbStateId.Value && p.DestinationStateId == destinationState.DbStateId.Value
                       && (p.CommandId == command.Id || command.SkipCheckCommandId) && !p.TransitionInitiatorId.HasValue).ToList().FirstOrDefault();

                    if (demandAdjustmentHistoryItem == null)
                    {
                        demandAdjustmentHistoryItem = new DemandAdjustmentTransitionHistory()
                        {
                            Id = Guid.NewGuid(),
                            DemandAdjustmentId = demandAdjustmentUid,
                            DestinationStateId = destinationState.DbStateId.Value,
                            InitialStateId = initialState.DbStateId.Value,
                            CommandId =
                                (command.Id == WorkflowCommand.Unknown.Id
                                     ? (Guid?)null
                                     : command.Id),
                        };
                        context.DemandAdjustmentTransitionHistories.InsertOnSubmit(demandAdjustmentHistoryItem);
                    }

                    demandAdjustmentHistoryItem.TransitionInitiatorId = initiatorId;
                    demandAdjustmentHistoryItem.TransitionTime = DateTime.Now;
                    demandAdjustmentHistoryItem.Comment = comment;
                    var info = WorkflowStateService.GetWorkflowStateInfo(destinationState);
                    demandAdjustmentHistoryItem.Description = WorkflowCommand.GetCommandDescription(command,
                                                                                             info == null
                                                                                                 ? string.Empty
                                                                                                 : info.StateVisibleName);




                    context.SubmitChanges();
                }

                scope.Complete();
            }
        }
 private void WritePreHistory(Guid demandAdjustmentId, Budget2DataContext context, WorkflowState initialState,
                            WorkflowState destinationState, Guid? expectedInitiatorId, WorkflowCommand command, WorkflowState startState)
 {
     if (initialState.Order < startState.Order)
         return;
     var billDemndHistoryItem = new DemandAdjustmentTransitionHistory
     {
         Id = Guid.NewGuid(),
         DemandAdjustmentId = demandAdjustmentId,
         DestinationStateId = destinationState.DbStateId.Value,
         InitialStateId = initialState.DbStateId.Value,
         TransitionExpectedInitiatorId = expectedInitiatorId,
         CommandId = command.Id,
         Comment = string.Empty,
         Description = string.Empty
     };
     context.DemandAdjustmentTransitionHistories.InsertOnSubmit(billDemndHistoryItem);
 }