internal static void DeleteWorkflowState(int WorkflowStateId, int WorkflowId)
 {
     try
     {
         WorkflowState wState = GetAllStatesbyWorkflowID(WorkflowId).Where(a => a.StateID == WorkflowStateId).FirstOrDefault();
         if (wState != null && !wState.IsFirst && !wState.IsLast)
         {
             ClearAllWorkflowStatePermissionsByStateID(wState.StateID);
             wState.Delete();
             List <WorkflowState> wStates = GetAllStatesbyWorkflowID(WorkflowId).OrderBy(o => o.Order).ToList();
             if (wStates.Count >= 2)
             {
                 Workflow wflow = GetWorkflowbyID(WorkflowId);
                 UpdateSatesOrder(wStates, wflow, false, wState.Order);
                 CacheFactory.Clear(CacheFactory.Keys.Workflow);
             }
         }
     }
     catch (Exception ex) { Exceptions.LogException(ex); }
 }