public int UpdateWorkflowLevel(WorkflowLevelModel workflowlevel) { return AddWorkflowLevel(workflowlevel); }
public int AddWorkflowLevel(WorkflowLevelModel model) { if (model.WorkflowId > 0) { try { if (!string.IsNullOrEmpty(model.Name)) { var workflowlevel = _workflowLevels.Find(model.Id) ?? new WorkflowLevel(); Mapper.CreateMap<WorkflowLevelModel, WorkflowLevel>(); Mapper.Map(model, workflowlevel); var workflow = _workflowLevels.Fetch(w => w.WorkflowId == workflowlevel.WorkflowId && w.RefId==workflowlevel.RefId) .OrderBy(w => w.LevelOrder) .Select(w => w); var workflowLevels = workflow as IList<WorkflowLevel> ?? workflow.ToList(); if (workflowlevel.LevelOrder <= 0 ||workflowlevel.Id==0&& workflowLevels.Any(w => w.LevelOrder == workflowlevel.LevelOrder)) { var lastWorkFlow = workflowLevels.LastOrDefault(); workflowlevel.LevelOrder = lastWorkFlow == null ? 1 : lastWorkFlow.LevelOrder+1; } try { if (workflowlevel.Id > 0) { _workflowLevels.Update(workflowlevel); } else { _workflowLevels.Insert(workflowlevel); } return workflowlevel.Id; } catch (Exception ex) { throw new WorkflowConfigurationError( "Workflow Level must have a unique name or unique level Order per Workflow. " + ex.Message); } } else throw new WorkflowConfigurationError("Workflow Level cannot be added as the Level Name is empty."); } catch (Exception ex) { throw new WorkflowConfigurationError( "Workflow Level cannot be added as the level Order already exist." + ex.Message); } } else throw new WorkflowConfigurationError("Workflow Level not associated with any Workflow."); }