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> Create([Bind("ID,Name")] Operation operation)
        {
            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Post <Operation>(ConsulUri, operation);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(operation));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("ID,Name")] ViewCategory viewCategory)
        {
            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Post <ViewCategory>(ConsulUri, viewCategory);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewCategory));
        }
        public async Task <IActionResult> Create([Bind("ID,Field")] ChangeField changeField)
        {
            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Post <ChangeField>(ConsulUri, changeField);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(changeField));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("ID,Name")] CategoryType categoryType)
        {
            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Post <CategoryType>(ConsulUri, categoryType);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryType));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Date,Description")] Event @event)
        {
            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Post <Event>(ConsulUri, @event);

                SendMessageToBus(@event, this.Login("qwer"));
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Operation operation)
        {
            if (id != operation.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Put <Operation>(ConsulUri, id, operation);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(operation));
        }
Example #8
0
        // 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));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Field")] ChangeField changeField)
        {
            if (id != changeField.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Put <ChangeField>(ConsulUri, id, changeField);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(changeField));
        }
        // 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));
        }
Example #11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] CategoryType categoryType)
        {
            if (id != categoryType.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Put <CategoryType>(ConsulUri, id, categoryType);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryType));
        }
Example #12
0
        // 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));
        }
Example #13
0
        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));
        }
        // 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));
        }
Example #15
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] ViewCategory viewCategory)
        {
            if (id != viewCategory.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await NetworkMethodModel.Put <ViewCategory>(ConsulUri, id, viewCategory);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewCategory));
        }
Example #16
0
        // 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));
        }
Example #17
0
        // 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));
        }
Example #18
0
        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));
        }
Example #19
0
        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());
            }
        }
Example #20
0
        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);
        }
Example #21
0
        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());
            }
        }
Example #22
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>());
        }
Example #23
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"));
        }
Example #24
0
        public async Task <IActionResult> Delete(int id)
        {
            await NetworkMethodModel.Delete(_consulWrapper["track-api"]["Scenerios"], id);

            return(RedirectToAction("Index"));
        }
Example #25
0
 // GET: CategoryTypes
 public async Task <IActionResult> Index()
 {
     return(View(await NetworkMethodModel.GetAll <CategoryType>(ConsulUri)));
 }
Example #26
0
        public async Task <IActionResult> Edit(int id)
        {
            var scenerio = await NetworkMethodModel.Get <Scenerio>(_consulWrapper["track-api"]["Scenerios"], id);

            return(View(scenerio));
        }
Example #27
0
 public async Task <IActionResult> Index()
 {
     return(View(await NetworkMethodModel.GetAll <Scenerio>(ConsulUri)));
 }
Example #28
0
        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);
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            await NetworkMethodModel.Delete(ConsulUri, id);

            return(RedirectToAction(nameof(Index)));
        }