Ejemplo n.º 1
0
        public async Task <IActionResult> PutAction(int id, CommonLibrary.DatabaseModels.Action action)
        {
            if (id != action.ID)
            {
                return(BadRequest());
            }

            _context.Entry(action).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ActionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public static bool HandlerTask(Task task, CommonLibrary.DatabaseModels.Action action, List <CommonLibrary.Clients.Model.User> usersworker)
        {
            foreach (var valid in action.ChangeFields)
            {
                if (valid.ChangeField.Field == "Worker")
                {
                    task.Worker = usersworker[0].ID;
                }
            }

            foreach (var valid in action.ValidateActions)
            {
                if (!ValidateStatic.IsValidOption(valid.ValidateField, task))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        private async Task <List <string> > ToNextState(int id, bool ignore)
        {
            if (!this.IsAuth())
            {
                return(null);
            }
            var user = this.GetUserByToken(this.Token());

            var valid = IsValid(id);
            var task  = await context.Tasks.FirstOrDefaultAsync(x => x.ID == id);

            var actionID = task.ChangeLogs.OrderByDescending(x => x.DateTime).First().Action;
            var action   = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], actionID);

            if (!ignore && ((UserType)action.UserType).ToString().ToLower() != user.Role.ToLower())
            {
                return(null);
            }

            var validResult = await valid;

            if (validResult.Count > 0)
            {
                return(validResult);
            }

            using (HttpClient client = new HttpClient())
            {
                var res = await client.GetAsync($"{consulWrapper["track-api"]["Actions"]}/nextaction?id={actionID}");

                List <CommonLibrary.DatabaseModels.Action> actions =
                    await res.Content.ReadAsAsync <List <CommonLibrary.DatabaseModels.Action> >();

                CommonLibrary.DatabaseModels.Action newAct = null;
                if (actions.Count != 0)
                {
                    newAct = actions[0];
                }
                else
                {
                    newAct = null;
                }
                context.ChangeLogs.Add(new ChangeLog
                {
                    Action   = newAct?.ID ?? -1,
                    Creator  = user.ID,
                    DateTime = DateTime.Now,
                    Task     = task,
                });
                context.SaveChanges();

                if (newAct != null && newAct.ID != -1 && newAct.IsAuto)
                {
                    var userRes = await client.GetAsync("http://172.20.10.6:8000/api/Users?role=worker");

                    var users = await userRes.Content.ReadAsAsync <List <CommonLibrary.Clients.Model.User> >();

                    if (AutoWorker.HandlerTask(task, action, users))
                    {
                        await Save(task);
                        await ToNextState(task.ID, true);
                    }
                }
            }

            await SendEmail(task, action, AdressType.State);

            return(new List <string>());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostCreate()
        {
            var scenario = new Scenerio
            {
                Json           = Request.Query["json"],
                CategoryID     = int.Parse(Request.Query["category"]),
                TypeID         = int.Parse(Request.Query["categorytype"]),
                Name           = Request.Query["name"],
                ScenerioTasks  = new List <ScenerioTask>(),
                ViewCategoryID = int.Parse(Request.Query["categoryView"])
            };

            var track = new Track {
            };

            scenario.ScenerioTasks.Add(new ScenerioTask {
                Scenerio = scenario, Track = track
            });

            var flows = Request.Query.Where(x => x.Key.Contains("usertype_")).Select(x => x.Key.Replace("usertype_", string.Empty));

            foreach (var flow in flows)
            {
                var action = new CommonLibrary.DatabaseModels.Action
                {
                    IsAuto          = Request.Query.ContainsKey($"auto_{flow}"),
                    ChangeFields    = new List <ChangeFieldInAction>(),
                    ValidateActions = new List <ValidateAction>(),
                    UserType        = (UserType)int.Parse(Request.Query[$"usertype_{flow}"]),
                    DaysCount       = int.Parse(Request.Query[$"day_{flow}"]),
                    State           = await NetworkMethodModel.Get <State>(_consulWrapper["track-api"]["States"], int.Parse(Request.Query[$"from_{flow}"])),
                    NextState       = await NetworkMethodModel.Get <State>(_consulWrapper["track-api"]["States"], int.Parse(Request.Query[$"to_{flow}"])),
                };
                track.ActionInTracks.Add(new ActionInTrack {
                    Action = action, Track = track
                });

                var groupFields = Request.Query.Where(x => x.Key.Contains($"select_{flow}")).ToList();
                foreach (var field in groupFields)
                {
                    action.ChangeFields.Add(new ChangeFieldInAction
                    {
                        Action      = action,
                        ChangeField = (await NetworkMethodModel.GetByName <ChangeField>(_consulWrapper["track-api"]["ChangeFields"], field.Value))
                    });
                }

                var groupValid = Request.Query.Where(x => x.Key.StartsWith(flow)).GroupBy(x => x.Key.Substring(x.Key.IndexOf("comp")));
                foreach (var validGroup in groupValid)
                {
                    action.ValidateActions.Add(new ValidateAction
                    {
                        Action        = action,
                        ValidateField = new ValidateField
                        {
                            Field     = validGroup.First().Value,
                            Operation = (await NetworkMethodModel.GetByName <Operation>(_consulWrapper["track-api"]["Operations"], validGroup.ElementAt(1).Value)),
                            With      = validGroup.Last().Value
                        }
                    });
                }
            }

            await NetworkMethodModel.Post(_consulWrapper["track-api"]["Scenerios"], scenario);

            return(Redirect("Index"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <CommonLibrary.DatabaseModels.Action> > PostAction(CommonLibrary.DatabaseModels.Action action)
        {
            _context.Actions.Add(action);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAction", new { id = action.ID }, action));
        }