Beispiel #1
0
        public WFFileStatePOCO(WFFileState wfState)
        {
            this.Id = wfState.Id;
            this.TS = wfState.TS;

            this.Notes = wfState.Notes.Select(s => new WFFileStateNotePOCO(s));
            this.State = new WFStatePOCO(wfState.WFState);
            this.User  = new UserPOCO(wfState.User);
        }
Beispiel #2
0
        public IResultServiceModel <WFFileState> SetStateForFile(long fileId, string userId, string wfStateCode, string userComment = null)
        {
            IResultServiceModel <WFFileState> rm = new ResultServiceModel <WFFileState>();
            var now = DateTime.Now;

            //Get Default Workflow For Files
            var wfCode = this.appConfigurationService.DefaultFileWorkflowCode;

            var rmIS = this.wfStateRepository.GetSpecificStateByCode(wfCode, wfStateCode);

            if (rmIS.Success)
            {
                var state = rmIS.Value;
                var fHis  = new WFFileState()
                {
                    EntityId  = fileId,
                    UserId    = userId,
                    WFStateId = rmIS.Value.Id,
                    TS        = now
                };

                if (string.IsNullOrEmpty(userComment))
                {
                    userComment = state.Name;
                }

                fHis.Notes.Add(new WFFileStateNote()
                {
                    UserId = userId, TS = now, Comment = userComment
                });

                this.wfFileStateRepository.Add(fHis);
                var rmSave = this.wfFileStateRepository.Save();

                if (rmSave.Success)
                {
                    rm = this.wfFileStateRepository.GetById(fHis.Id);
                }
                else
                {
                    rm.OnError(rmSave.ErrorMessage, rmSave.ErrorCode);
                }
            }
            else
            {
                rm.OnError(rmIS.ErrorMessage, rmIS.ErrorCode);
            }

            return(rm);
        }
Beispiel #3
0
        public IResultServiceModel <WFFileState> SetInitialStateForFile(File file, string userId)
        {
            IResultServiceModel <WFFileState> rm = new ResultServiceModel <WFFileState>();
            var        now      = DateTime.Now;
            WFWorkflow workflow = null;
            string     wfCode   = this.appConfigurationService.DefaultFileWorkflowCode;

            //Get the customer for the file before to find out what Workflow it needs
            if (file.WFWorkflow != null)
            {
                workflow = file.WFWorkflow;
                wfCode   = workflow.Code;
            }
            else if (file.WFWorkflowId.HasValue)
            {
                var rmWF = this.GetWorkflowById(file.WFWorkflowId.Value);
                if (rmWF.Success)
                {
                    workflow = rmWF.Value;
                }
                else
                {
                    workflow = null;
                }
            }

            if (workflow == null)
            {
                var rmWF = this.GetWorkflowByCode(wfCode);
                if (rmWF.Success)
                {
                    workflow = rmWF.Value;
                }
                else
                {
                    workflow = null;
                }
            }

            var rmIS = this.wfStateRepository.GetInitialStateByWorkflowCode(wfCode);

            if (rmIS.Success)
            {
                var state = rmIS.Value;
                if (workflow == null)
                {
                    workflow = state.WFWorkflows.Where(w => w.WFWorkflow.Code == wfCode).Select(w => w.WFWorkflow).FirstOrDefault();
                }

                //put the workflow id and version to the file;
                if (workflow != null)
                {
                    file.WFWorkflowId      = workflow.Id;
                    file.WFWorkflowVersion = workflow.WFWorkflowVersion;
                    this.fileRepository.Update(file);
                    this.fileRepository.Save();
                }


                var fHis = new WFFileState()
                {
                    EntityId  = file.Id,
                    UserId    = userId,
                    WFStateId = rmIS.Value.Id,
                    TS        = now
                };

                fHis.Notes.Add(new WFFileStateNote()
                {
                    UserId = userId, TS = now, Comment = state.Name
                });

                this.wfFileStateRepository.Add(fHis);
                var rmSave = this.wfFileStateRepository.Save();

                if (rmSave.Success)
                {
                    rm = this.wfFileStateRepository.GetById(fHis.Id);
                    //rm.OnSuccess(state);
                }
                else
                {
                    rm.OnError(rmSave.ErrorMessage, rmSave.ErrorCode);
                }
            }
            else
            {
                rm.OnError(rmIS.ErrorMessage, rmIS.ErrorCode);
            }

            return(rm);
        }