public ActionResult UpdateRoutes(Guid id) { try { string message = null; var result = WorkflowOperations.UpdateRoutes(id, out message); if (!result) { return(GetErrorResult(message)); } return(GetSuccessResult()); } catch (Exception ex) { return(GetErrorResult(ex)); } }
private static bool Execute(Guid id, string name, string parameters, bool isSetState, out string message) { try { var commandParameters = GetParameters(parameters); if (commandParameters.Any(p => p.Key == "EntityRoute")) { var routeParam = commandParameters.Single(c => c.Key == "EntityRoute"); WorkflowOperations.SetRoute(id, new Guid(routeParam.Value.ToString())); } message = null; bool result; if (isSetState) { result = WorkflowOperations.SetState(id, name, commandParameters, out message); } else { result = WorkflowOperations.Execute(id, name, commandParameters, out message); } if (!result) { return(false); } return(true); } catch (Exception ex) { message = ex.Message; return(false); } }
private static ActionResult Execute(Guid id, string name, string parameters, bool isSetState) { try { var commandParameters = GetParameters(parameters); if (commandParameters.Any(p => p.Key == "EntityRoute")) { var routeParam = commandParameters.Single(c => c.Key == "EntityRoute"); WorkflowOperations.SetRoute(id, new Guid(routeParam.Value.ToString())); } string message = null; var result = false; if (isSetState) { result = WorkflowOperations.SetState(id, name, commandParameters, out message); } else { result = WorkflowOperations.Execute(id, name, commandParameters, out message); } if (!result) { return(GetErrorResult(message)); } return(GetSuccessResult()); } catch (Exception ex) { Logger.Log.Error(ex); return(GetErrorResult(ex)); } }
public ActionResult MultiGetState(string ids, string processName) { var idsList = ids.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => new Guid(x)).ToList(); var items = DynamicRepository.GetByEntity("BudgetItem", FilterCriteriaSet.And.In(idsList, "Id")).ToList(); var grouppedStates = new Dictionary <Guid, Tuple <string, List <object>, List <Guid>, List <long> > >(); var routeIds = items.Where(i => i.EntityRouteId != null).Select(i => (Guid)i.EntityRouteId).Distinct().ToList(); if (!routeIds.Any()) { return(GetSuccessResult()); } var routes = DynamicRepository.GetByEntity("EntityRoute", FilterCriteriaSet.And.In(routeIds, "Id")).ToList(); foreach (var route in routes) { var routeId = (Guid)route.Id; var states = WorkflowOperations.GetStates(routeId, processName); var routeStates = new Tuple <string, List <object>, List <Guid>, List <long> >( route.Name, states.Select(s => new { name = s.Name, text = s.VisibleName } as object).ToList(), items.Where(i => i.EntityRouteId == routeId).Select(i => (Guid)i.Id).ToList(), items.Where(i => i.EntityRouteId == routeId).Select(i => (long)i.NumberId).ToList()); grouppedStates.Add(routeId, routeStates); } if (!grouppedStates.Any()) { return(GetSuccessResult()); } var sb = new StringBuilder("["); bool isFirst = true; foreach (var c in grouppedStates) { if (!isFirst) { sb.Append(","); } isFirst = false; var item = new { routeid = c.Key, routename = c.Value.Item1, ids = c.Value.Item3.ToFormattedString(",", false), numbers = c.Value.Item4.ToFormattedString(", ", false), states = JsonSerializer.SerializeToString(c.Value.Item2) }; sb.Append(JsonSerializer.SerializeToString(item)); } sb.Append("]"); if (sb.Length > 0) { return(new ContentResult { ContentEncoding = Encoding.UTF8, Content = string.Format("{{\"success\" : true, \"values\" : {0}}}", sb) }); } return(GetSuccessResult()); }
public ActionResult MultiGetCommand(string ids, string processName) { var idsList = ids.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => new Guid(x)).ToList(); //var numbersList = numbers.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => int.Parse(x)).ToList(); var items = DynamicRepository.GetByEntity("BudgetItem", FilterCriteriaSet.And.In(idsList, "Id")).ToList(); var grouppedCommands = new Dictionary <string, Tuple <WorkflowCommand, List <Guid>, List <long> > >(); for (int i = 0; i < idsList.Count; i++) { var id = idsList[i]; var item = items.FirstOrDefault(bi => bi.Id.Equals(id)); if (item == null) { continue; } var commands = BudgetItem.GetCommands(item); foreach (var command in commands) { Tuple <WorkflowCommand, List <Guid>, List <long> > value; if (grouppedCommands.ContainsKey(command.CommandName)) { value = grouppedCommands[command.CommandName]; } else { value = new Tuple <WorkflowCommand, List <Guid>, List <long> >(command, new List <Guid>(), new List <long>()); grouppedCommands.Add(command.CommandName, value); } value.Item2.Add(id); value.Item3.Add(item.NumberId); } } if (!grouppedCommands.Any()) { return(GetSuccessResult()); } var sb = new StringBuilder("["); bool isFirst = true; foreach (var c in grouppedCommands) { if (!isFirst) { sb.Append(","); } isFirst = false; var item = new { ids = c.Value.Item2.ToFormattedString(",", false), numbers = c.Value.Item3.ToFormattedString(", ", false), command = WorkflowOperations.ConvertWorkflowCommandToJSON(c.Value.Item1) }; sb.Append(JsonSerializer.SerializeToString(item)); } sb.Append("]"); if (sb.Length > 0) { var routes = WorkflowOperations.GetFormattedRoutesForUser(CommonSettings.CurrentEmployee.SecurityUserId); return(new ContentResult { ContentEncoding = Encoding.UTF8, Content = string.Format("{{\"success\" : true, \"values\" : {0},\"routes\": {1}}}", sb, routes) }); } return(GetSuccessResult()); }