public async Task <ActionResult> EditCondition(MatcherViewModel model, string updateButton)
        {
            string previousPage = CacheHelper.GetPreviousPage(_cache);

            if (updateButton.Equals("Cancel"))
            {
                return(Redirect(previousPage));
            }

            var matcher = await DigitalTwinsHelper.GetMatcherAsync(model.SelectedMatcher.Id, _cache, Loggers.SilentLogger, false);

            if (matcher != null)
            {
                var index = matcher.Conditions.FindIndex(m => m.Id == model.SelectedMatcherCondition.Id);

                if (updateButton.Equals("Update"))
                {
                    matcher.Conditions[index] = model.SelectedMatcherCondition;
                }

                if (updateButton.Equals("Delete"))
                {
                    matcher.Conditions.RemoveAt(index);
                }

                CacheHelper.AddInCache(_cache, matcher, matcher.Id, Context.Matcher);
            }
            return(Redirect(previousPage));
        }
        public async Task <ActionResult> Edit(MatcherViewModel model, string updateButton)
        {
            string previousPage = CacheHelper.GetPreviousPage(_cache);

            if (updateButton.Equals("Cancel"))
            {
                return(Redirect(previousPage));
            }

            // we load the matcher in cache to restore the conditions previously defined
            var matcher = await DigitalTwinsHelper.GetMatcherAsync(model.SelectedMatcher.Id, _cache, Loggers.SilentLogger, false);

            matcher.Name = model.SelectedMatcher.Name;

            // we update the matcher
            await DigitalTwinsHelper.UpdateMatcherAsync(matcher, _cache, Loggers.SilentLogger);

            // we associate the matcher with the UDF
            //var udf = await DigitalTwinsHelper.GetUserDefinedFunction(model.UdfId, _cache, Loggers.SilentLogger, false);
            //udf.Matchers.Add(matcher);
            //await DigitalTwinsHelper.UpdateUserDefinedFunctionAsync(_cache, Loggers.SilentLogger, udf);

            //we remove the matcher from the cache
            CacheHelper.AddInCache(_cache, null, Guid.Empty, Context.Matcher);

            return(RedirectToAction("Edit", "UDF", new { id = model.UdfId }));
        }
        public ActionResult AddCondition()
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());
            MatcherViewModel model = new MatcherViewModel(_cache);

            return(View(model));
        }
        public ActionResult Edit(Guid matcherId, Guid udfId)
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());
            MatcherViewModel model = new MatcherViewModel(_cache, id: matcherId);

            model.UdfId = udfId;
            return(View(model));
        }
        public ActionResult EditCondition(Guid matcherId, Guid conditionId)
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());

            MatcherViewModel model = new MatcherViewModel(_cache, id: matcherId);

            model.SelectedMatcherCondition = model.SelectedMatcher.Conditions.FirstOrDefault(m => m.Id == conditionId);
            return(View(model));
        }
        public async Task <ActionResult> AddCondition(MatcherViewModel model, string createButton)
        {
            string previousPage = CacheHelper.GetPreviousPage(_cache);

            var matcher = await DigitalTwinsHelper.GetMatcherAsync(model.SelectedMatcher.Id, _cache, Loggers.SilentLogger, false);

            if (matcher != null)
            {
                matcher.Conditions.Add(model.SelectedMatcherCondition);
                CacheHelper.AddInCache(_cache, matcher, matcher.Id, Context.Matcher);
            }
            return(Redirect(previousPage));
        }
        public async Task <ActionResult> Delete(MatcherViewModel model, string updateButton)
        {
            string previousPage = CacheHelper.GetPreviousPage(_cache);

            if (updateButton.Equals("Cancel"))
            {
                return(Redirect(previousPage));
            }

            await DigitalTwinsHelper.DeleteMatcherAsync(model.SelectedMatcher, _cache, Loggers.SilentLogger);

            return(RedirectToAction("Edit", "UDF", new { id = model.UdfId }));
        }