public async System.Threading.Tasks.Task <List <int> > Create(CreateTask createTask) { if (!this.IsAuth()) { return(null); } var user = this.GetUserByToken(this.Token()); List <CommonLibrary.DatabaseModels.Task> tasks = new List <CommonLibrary.DatabaseModels.Task>(); using (var client = new HttpClient()) { try { var res = await client.GetAsync($"{consulWrapper["recognition-api"]["Recognition"]}/ChoiceCategory?data={createTask.Data}"); ChoiceCategory choice = await res.Content.ReadAsAsync <ChoiceCategory>(); tasks.AddRange(await GenerateTrack(choice, client, createTask, user)); } catch (Exception) { } client.DefaultRequestHeaders.Add("token", this.Login("qwer")); 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> >(); foreach (var task in tasks) { int actionID = task.ChangeLogs.First().Action; var action = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], actionID); if (action.IsAuto) { if (AutoWorker.HandlerTask(task, action, users)) { await Save(task); await ToNextState(task.ID, true); } } } return(tasks.Select(x => x.ID).ToList()); } }
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>()); }