public async Task <IActionResult> CreateTree(RequestCreateModel model1) { var process = new Process(model1.Process.Name); _context.Processes.Add(process); await _context.SaveChangesAsync(); Model.Request new_request = Model.Request.NodeCreateFlow(model1, process); _context.Requests.Add(new_request); await _context.SaveChangesAsync(); foreach (var rule in new_request.Process.Rules) { var f = await _context.Nodes.FirstOrDefaultAsync(r => r.Id == rule.CurrentNode.Id); var s = await _context.Nodes.FirstOrDefaultAsync(r => r.Id == rule.NextNode.Id); if (f != null && s != null) { f.AddChild(s); _context.Update(f); } } await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> CreateWorkFlow(RequestCreateModel model1) { Model.Request new_request = Model.Request.CreateFlow(model1); _context.Requests.Add(new_request); await _context.SaveChangesAsync(); return(Ok(_mapper.Map <RequestViewModel>(new_request))); }
public static Model.Request NodeCreateFlow(RequestCreateModel model1, Process process) { if (model1 is null) { return(null); } if (model1.Process is null) { return(null); } process.Actions = new List <Models.Action>(); process.States = new List <State>(); process.Rules = new List <TransitionRule>(); process.Roles = new List <Role>(); process.Activities = new List <Activity>(); process.Nodes = new List <Node>(); foreach (var node in model1.Process.Nodes) { Node new_node = new Node { Level = node.Level, Name = node.Name, Description = node.Description, Activities = new List <Activity>(), Iscompleted = node.Iscompleted, Roles = new List <Role>(), Actions = new List <Models.Action>(), Childs = new List <Node>() }; if (node.Actions != null) { foreach (var action in node.Actions) { var new_action = new Models.Action { Name = action.Name, Description = action.Description }; new_node.Actions.Add(new_action); process.Actions.Add(new_action); } } foreach (var activity in node.Activities) { if (activity.ActivityType == ActivityType.Email) { Activity new_activity = new EmailActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Discriminator = "EMAIL", Roles = new List <Role>(), Data = new List <Data>() }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_node.Roles.Add(new_role); } process.Activities.Add(new_activity); new_node.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Absent) { Activity new_activity = new TLActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Discriminator = "TALENT-LEAVE", Roles = new List <Role>(), Data = new List <Data>(), AbsentName = activity.AbsentName, ApproverName = activity.ApproverName, DayOff = activity.DayOff, IsReallyNotApproved = activity.IsReallyNotApproved, Reason = activity.Reason }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_node.Roles.Add(new_role); } process.Activities.Add(new_activity); new_node.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Generic) { Activity new_activity = new GenericActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Roles = new List <Role>(), Data = new List <Data>(), }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_node.Roles.Add(new_role); } process.Activities.Add(new_activity); new_node.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Campaign) { Activity new_activity = new CampaignActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, CampaignName = activity.CampaignName, Subscribers = new List <Contact>(), IsRunning = activity.IsRunning, Roles = new List <Role>(), Data = new List <Data>(), Discriminator = "CAMPAIGN" }; // if (activity.Subscribers != null) // { // foreach (var item in activity.Subscribers) // { // ((CampaignActivityOperator)new_activity).Subscribers.Add(new Contact { // FullName = item.FullName, // Email = item.Email, // PhoneNumber = item.PhoneNumber, // Age = item.Age, // DataType = DataType.Contact // }) // } // } if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_node.Roles.Add(new_role); } process.Activities.Add(new_activity); new_node.Activities.Add(new_activity); } } } process.Nodes.Add(new_node); } if (model1.Process.Rules != null) { foreach (var rule in model1.Process.Rules) { TransitionRule new_rule = new TransitionRule { CurrentNode = process.Nodes.FirstOrDefault(s => s.Name == rule.CurrentNode.Name), NextNode = process.Nodes.FirstOrDefault(s => s.Name == rule.NextNode.Name), Action = process.Actions.FirstOrDefault(a => a.Name == rule.Action.Name) }; process.Rules.Add(new_rule); } } var new_request = new Model.Request { Title = model1.Title, UserId = model1.UserId, UserName = model1.UserName, CurrentNode = process.Nodes.FirstOrDefault(s => s.Level == 0), DateRequested = model1.DateRequested, Histories = new List <ActivityLog>(), Tasks = new List <Model.Task>(), Data = new List <Data>() }; new_request.Process = process; new_request.Tasks = new List <Model.Task>(); foreach (var activity in process.Activities) { new_request.Tasks.Add(new Model.Task { Activity = activity, IsDone = false }); } return(new_request); }
public static Model.Request CreateFlow(RequestCreateModel model1) { if (model1 is null) { return(null); } if (model1.Process is null) { return(null); } Process new_process = new Process { Name = model1.Process.Name, Actions = new List <Models.Action>(), States = new List <State>(), Rules = new List <TransitionRule>(), Roles = new List <Role>(), Activities = new List <Activity>() }; foreach (var state in model1.Process.States) { State new_state = new State { StateType = state.StateType, Name = state.Name, Description = state.Description, Activities = new List <Activity>(), Roles = new List <Role>(), ETA = state.ETA }; foreach (var activity in state.Activities) { if (activity.ActivityType == ActivityType.Email) { Activity new_activity = new EmailActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Discriminator = "EMAIL", Roles = new List <Role>(), Data = new List <Data>() }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; new_process.Roles.Add(new_role); new_activity.Roles.Add(new_role); } new_process.Activities.Add(new_activity); new_state.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Absent) { Activity new_activity = new TLActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Discriminator = "TALENT-LEAVE", Roles = new List <Role>(), Data = new List <Data>(), AbsentName = activity.AbsentName, ApproverName = activity.ApproverName, DayOff = activity.DayOff, IsReallyNotApproved = activity.IsReallyNotApproved, Reason = activity.Reason }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; new_process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_state.Roles.Add(new_role); } new_process.Activities.Add(new_activity); new_state.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Generic) { Activity new_activity = new GenericActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, Roles = new List <Role>(), Data = new List <Data>(), }; if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; new_process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_state.Roles.Add(new_role); } new_process.Activities.Add(new_activity); new_state.Activities.Add(new_activity); } } else if (activity.ActivityType == ActivityType.Campaign) { Activity new_activity = new CampaignActivityOperator { ActivityType = activity.ActivityType, Name = activity.Name, Description = activity.Description, Duration = activity.Duration, IsRequired = activity.IsRequired, CampaignName = activity.CampaignName, Subscribers = new List <Contact>(), IsRunning = activity.IsRunning, Roles = new List <Role>(), Data = new List <Data>(), Discriminator = "CAMPAIGN" }; // if (activity.Subscribers != null) // { // foreach (var item in activity.Subscribers) // { // ((CampaignActivityOperator)new_activity).Subscribers.Add(new Contact { // FullName = item.FullName, // Email = item.Email, // PhoneNumber = item.PhoneNumber, // Age = item.Age, // DataType = DataType.Contact // }) // } // } if (activity.Roles != null) { foreach (var role in activity.Roles) { Role new_role = new Role { Name = role.Name }; new_process.Roles.Add(new_role); new_activity.Roles.Add(new_role); new_state.Roles.Add(new_role); } new_process.Activities.Add(new_activity); new_state.Activities.Add(new_activity); } } } new_process.States.Add(new_state); } if (model1.Process.Actions != null) { foreach (var action in model1.Process.Actions) { var new_action = new Models.Action { Name = action.Name, Description = action.Description }; new_process.Actions.Add(new_action); } } if (model1.Process.Rules != null) { foreach (var rule in model1.Process.Rules) { TransitionRule new_rule = new TransitionRule { CurrentState = new_process.States.FirstOrDefault(s => s.Name == rule.CurrentState.Name), NextState = new_process.States.FirstOrDefault(s => s.Name == rule.NextState.Name), Action = new_process.Actions.FirstOrDefault(a => a.Name == rule.Action.Name) }; // if (rule.Trigger != null) { // var new_trigger = new Trigger { // Consequence = rule.Trigger.Consequence, // Events = rule.Trigger.Events // }; // new_rule.Trigger = new_trigger; // } new_process.Rules.Add(new_rule); } } var new_request = new Model.Request { Title = model1.Title, UserId = model1.UserId, UserName = model1.UserName, CurrentState = new_process.States.FirstOrDefault(s => s.StateType == StateType.start), DateRequested = model1.DateRequested, Histories = new List <ActivityLog>(), Tasks = new List <Model.Task>(), Data = new List <Data>() }; new_request.Process = new_process; new_request.Tasks = new List <Model.Task>(); foreach (var activity in new_process.Activities) { new_request.Tasks.Add(new Model.Task { Activity = activity, IsDone = false }); } return(new_request); }