// GET: Operations/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var operation = await NetworkMethodModel.Get <Operation>(ConsulUri, id.Value); if (operation == null) { return(NotFound()); } return(View(operation)); }
// GET: ViewCategories/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var viewCategory = await NetworkMethodModel.Get <ViewCategory>(ConsulUri, id.Value); if (viewCategory == null) { return(NotFound()); } return(View(viewCategory)); }
// GET: ChangeFields/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var changeField = await NetworkMethodModel.Get <ChangeField>(ConsulUri, id.Value); if (changeField == null) { return(NotFound()); } return(View(changeField)); }
// GET: CategoryTypes/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var categoryType = await NetworkMethodModel.Get <CategoryType>(ConsulUri, id.Value); if (categoryType == null) { return(NotFound()); } return(View(categoryType)); }
// GET: Events/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } var @event = await NetworkMethodModel.Get <Event>(ConsulUri, id.Value); if (@event == null) { return(NotFound()); } return(View(@event)); }
// GET: States/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } var state = await NetworkMethodModel.Get <State>(ConsulUri, id.Value); if (state == null) { return(NotFound()); } return(View(state)); }
public async Task <CommonLibrary.DatabaseModels.Action> GetCurrentAction(int id) { if (!this.IsAuth()) { return(null); } if (context.Tasks.FirstOrDefault(x => x.ID == id) == null) { return(null); } var lastChangeLog = context.ChangeLogs.Where(x => x.Task.ID == id).OrderByDescending(x => x.DateTime).First(); return(await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], lastChangeLog.Action)); }
public async Task <IActionResult> EditConfirmed() { var root = JsonConvert.DeserializeObject <RootObject>(Request.Form["data"]); ViewBag.Scenerio = await NetworkMethodModel.Get <Scenerio>(_consulWrapper["track-api"]["Scenerios"], int.Parse(Request.Form["id"])); ViewBag.States = await NetworkMethodModel.GetAll <State>(_consulWrapper["track-api"]["States"]); ViewBag.ChangeField = await NetworkMethodModel.GetAll <ChangeField>(_consulWrapper["track-api"]["ChangeFields"]); ViewBag.Operations = await NetworkMethodModel.GetAll <Operation>(_consulWrapper["track-api"]["Operations"]); ViewBag.Category = new SelectList(await NetworkMethodModel.GetAll <Category>(_consulWrapper["track-api"]["Categories"]), "ID", "Name"); ViewBag.ViewCategory = new SelectList(await NetworkMethodModel.GetAll <ViewCategory>(_consulWrapper["track-api"]["ViewCategories"]), "ID", "Name"); ViewBag.CategoryType = new SelectList(await NetworkMethodModel.GetAll <CategoryType>(_consulWrapper["track-api"]["CategoryTypes"]), "ID", "Name"); return(View("PostEdit", root)); }
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()); } }
public async Task <List <string> > IsValid(int id) { if (!this.IsAuth()) { return(null); } List <string> invalid = new List <string>(); var task = context.Tasks.FirstOrDefault(x => x.ID == id); var taskActionLast = context.ChangeLogs.Where(x => x.Task.ID == id).OrderByDescending(x => x.DateTime).First().Action; var action = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], taskActionLast); foreach (var valid in action.ValidateActions) { var res = ValidateStatic.IsValidOption(valid.ValidateField, task); if (!res) { invalid.Add(valid.ValidateField.Field); } } return(invalid); }
public async Task <List <int> > Emergency() { if (!this.IsAuth()) { return(null); } using (HttpClient client = new HttpClient()) { var user = this.GetUserByToken(this.Token()); var choice = await NetworkMethodModel.Get <CategoryType>(consulWrapper["track-api"]["CategoryTypes"], 1054); return((await GenerateTrack(new ChoiceCategory { Category = choice.ViewCategory.Category.ID, CategoryType = choice.ID, ViewCategory = choice.ViewCategory.ID }, client, new CreateTask { Name = "Помогите!" }, user)).Select(x => x.ID).ToList()); } }
public async Task <List <TaskAbout> > GetUsersTasks() { if (!this.IsAuth()) { return(null); } List <TaskAbout> tasks = new List <TaskAbout>(); using (HttpClient client = new HttpClient()) { try { var roleUser = this.GetUserByToken(this.Token()); if (roleUser.Role.ToLower() == "worker") { foreach (var task in context.Tasks.Where(x => x.Worker == roleUser.ID)) { var action = task.ChangeLogs.OrderByDescending(x => x.DateTime).First(); tasks.Add(new TaskAbout { IsEnd = task.ChangeLogs.Any(x => x.Action == -1), Task = task }); } } if (roleUser.Role.ToLower() == "user") { foreach (var task in context.Tasks.Where(x => x.ChangeLogs.OrderBy(y => y.DateTime).First().Creator == roleUser.ID)) { var action = task.ChangeLogs.OrderByDescending(x => x.DateTime).First(); tasks.Add(new TaskAbout { IsEnd = task.ChangeLogs.Any(x => x.Action == -1), Task = task }); } } else { foreach (var task in context.Tasks) { var actionId = task.ChangeLogs.OrderByDescending(x => x.DateTime).First(); var action = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], actionId.Action); if (action?.UserType == UserType.Moder) { tasks.Add(new TaskAbout { IsEnd = actionId.Action == -1, Task = task }); } } } } catch (Exception) { } } foreach (var task in tasks) { foreach (var ch in task.Task.ChangeLogs) { ch.ActionResult = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], ch.Action); } } return(tasks); }
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>()); }
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")); }
public async Task <IActionResult> Edit(int id) { var scenerio = await NetworkMethodModel.Get <Scenerio>(_consulWrapper["track-api"]["Scenerios"], id); return(View(scenerio)); }