public async Task <ActionResult <Scenerio> > DeleteScenerio(int id) { var scenerio = await context.Scenerios.FindAsync(id); if (scenerio == null) { return(NotFound()); } var sceneriosActions = context.ScenerioTasks.Where(x => x.Scenerio.ID == id); context.RemoveRange(sceneriosActions); var tracks = sceneriosActions.Select(x => x.Track); var actions = tracks.Select(x => x.ActionInTracks.Select(y => y.Action)).SelectMany(x => x); context.RemoveRange(tracks.Select(x => x.ActionInTracks).SelectMany(x => x)); context.RemoveRange(actions.Select(x => x.ChangeFields).SelectMany(x => x)); context.RemoveRange(actions.Select(x => x.ValidateActions).SelectMany(x => x)); context.RemoveRange(actions); context.RemoveRange(tracks); context.Scenerios.Remove(scenerio); var listTask = await NetworkMethodModel.GetAll <CommonLibrary.DatabaseModels.Task>(consulWrapper["task-api"]["Tasks"]); foreach (var task in listTask.Where(x => x.Scenario == id).Select(x => x.ID)) { await NetworkMethodModel.Delete(consulWrapper["task-api"]["Tasks"], task); } await context.SaveChangesAsync(); return(scenerio); }
public async Task <IActionResult> CreateConfirmed() { var root = JsonConvert.DeserializeObject <RootObject>(Request.Form["data"]); 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("PostCreate", root)); }
public async Task <IActionResult> Index() { return(View(await NetworkMethodModel.GetAll <Scenerio>(ConsulUri))); }
public async Task <IActionResult> PostEdit() { var scenario = await NetworkMethodModel.Get <Scenerio>(_consulWrapper["track-api"]["Scenerios"], int.Parse(Request.Query["id"])); scenario.Json = Request.Query["json"]; scenario.ID = int.Parse(Request.Query["id"]); scenario.CategoryID = int.Parse(Request.Query["category"]); scenario.TypeID = int.Parse(Request.Query["categorytype"]); scenario.Name = Request.Query["name"]; scenario.ViewCategoryID = int.Parse(Request.Query["categoryView"]); var tracks = (await NetworkMethodModel.GetAll <Track>(_consulWrapper["track-api"]["Tracks"])) .Where(x => scenario.ScenerioTasks.Any(y => y.Track.ID == x.ID)); foreach (var t in tracks) { await NetworkMethodModel.Delete(_consulWrapper["track-api"]["Tracks"], t.ID); } scenario.ScenerioTasks = new List <ScenerioTask>(); 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.Put(_consulWrapper["track-api"]["Scenerios"], scenario.ID, scenario); return(Redirect("Index")); }
// GET: CategoryTypes public async Task <IActionResult> Index() { return(View(await NetworkMethodModel.GetAll <CategoryType>(ConsulUri))); }