public static bool IsOpen(Guid instanceId)
 {
     ActionItemWorkflow item = new ActionItemWorkflow(instanceId);
     if (item.IsCompleted)
         return false;
     return true;
 }
 public static bool RequestTransition(int id, int requestedBy)
 {
     using (ActionTrackerEntities db = new ActionTrackerEntities())
     {
         ActionItem item = db.ActionItems.Find(id);
         ActionItemWorkflow wf = new ActionItemWorkflow((Guid)item.InstanceId);
         wf.TryAdvance(requestedBy);
     }
     return true;
 }
        public static bool CanUserRequestTransition(int id, int requestedBy)
        {
            using (ActionTrackerEntities db = new ActionTrackerEntities())
            {
                ActionItem item = db.ActionItems.Find(id);
                ActionList list = db.ActionLists.Find(item.ActionListId);
                ActionItemWorkflow wf = new ActionItemWorkflow((Guid)item.InstanceId);

                if (wf.CurrentState.Name.ToLower() == "open")
                {
                    return true;
                }
                else if (requestedBy == item.AssignedTo || requestedBy == list.CreatedBy || wf.IsCompleted == false)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        public static bool Save(string userName, ElSignatureType sigType, ActionItem cachedItem)
        {
            try
            {
                //get audit trail items
                List<AuditTrail> atItems = new List<AuditTrail>();
                if(cachedItem.ActionItemId>0)
                    atItems = getAuditTrailItems(cachedItem);

                //If Create/Edit/Remove
                int recordId = 0;
                if (sigType == ElSignatureType.Record_Create || sigType == ElSignatureType.Record_Edit || sigType == ElSignatureType.Record_Remove)
                {
                    //SaveRecordData
                    recordId = saveRecordData(cachedItem, sigType);
                }

                //trap null value error;
                if (recordId == 0)
                    throw new NullReferenceException();

                if (sigType == ElSignatureType.Record_Create || sigType == ElSignatureType.Workflow_Create || sigType == ElSignatureType.Workflow_Transition)
                {
                    //SaveWorkflowData
                    using (ActionTrackerEntities db = new ActionTrackerEntities())
                    {
                        ActionItem loadedItem = db.ActionItems.Find(recordId);
                        ActionItemWorkflow aiwf = new ActionItemWorkflow();
                        Guid instanceId = aiwf.CreateInstance(loadedItem.ActionItemId, AccountRepos.GetAccountId(userName));

                        //update record with instanceId
                        loadedItem.InstanceId = instanceId;
                        db.Entry(loadedItem).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                //SaveESig();
                ESig es = new ESig()
                {
                    RecordId = recordId,
                    SignedBy = AccountRepos.GetAccountId(userName),
                    SignedDate = DateTime.Now,
                    TableName = typeof(ActionItem).Name,
                    IsComplete = true,
                    SignatureRole = enumToString(sigType)
                };
                using (ActionTrackerEntities db = new ActionTrackerEntities())
                {
                    db.Entry(es).State = EntityState.Added;
                    db.SaveChanges();

                    //update and save audit trail items with ESig and RecordIds, and changetype
                    foreach (AuditTrail item in atItems)
                    {
                        item.ESigId = es.ESigId;
                        item.RecordId = recordId;
                        item.ChangeType = es.SignatureRole;
                        db.Entry(item).State = EntityState.Added;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
                //TODO:
                //return false;
            }
            return true;
        }
 public MergedItem()
 {
     Workflow = new ActionItemWorkflow();
 }
 public MergedItem(ActionItem actionItem)
 {
     Item = actionItem;
     Workflow = new ActionItemWorkflow((Guid)actionItem.InstanceId);
 }