Beispiel #1
0
        public async void DeleteInstance()
        {
            bool confirmed = await JSRuntime.InvokeAsync <bool>("confirm", $"Are you sure you want to delete {Instance.Name}?");

            if (confirmed)
            {
                instanceService.DeleteInstance(Instance);
                Instances.DeleteInstance(Instance);
            }
        }
        private static void SearchAndDelete(Guid targetKey, Instances instancesController, Instance instance)
        {
            var aSecondInstance = new Instance() { Name = "A Second Instance", TargetKey = targetKey };
            instancesController.CreateInstance(aSecondInstance);
            var zThirdInstance = new Instance() { Name = "Z Third Instance", TargetKey = targetKey };
            instancesController.CreateInstance(zThirdInstance);

            var search1 = instancesController.SearchInstances(targetKey);
            Debug.Assert(search1.TotalCount == 3);
            Debug.Assert(search1.Instances.Count() == 3);
            Debug.Assert(search1.Instances.ElementAt(0).Key == aSecondInstance.Key);
            Debug.Assert(search1.Instances.ElementAt(1).Key == instance.Key);
            Debug.Assert(search1.Instances.ElementAt(2).Key == zThirdInstance.Key);

            var search2 = instancesController.SearchInstances(targetKey, "Test");
            Debug.Assert(search2.TotalCount == 1);
            Debug.Assert(search2.Instances.Count() == 1);
            Debug.Assert(search2.Instances.ElementAt(0).Key == instance.Key);

            var search3 = instancesController.SearchInstances(targetKey, pageSize: 1);
            Debug.Assert(search3.TotalCount == 3);
            Debug.Assert(search3.Instances.Count() == 1);
            Debug.Assert(search3.Instances.ElementAt(0).Key == aSecondInstance.Key);

            var search4 = instancesController.SearchInstances(targetKey, pageSize: 2);
            Debug.Assert(search4.TotalCount == 3);
            Debug.Assert(search4.Instances.Count() == 2);
            Debug.Assert(search4.Instances.ElementAt(0).Key == aSecondInstance.Key);
            Debug.Assert(search4.Instances.ElementAt(1).Key == instance.Key);

            var search5 = instancesController.SearchInstances(targetKey, offset: 1);
            Debug.Assert(search5.TotalCount == 3);
            Debug.Assert(search5.Instances.Count() == 2);
            Debug.Assert(search5.Instances.ElementAt(0).Key == instance.Key);
            Debug.Assert(search5.Instances.ElementAt(1).Key == zThirdInstance.Key);

            var search6 = instancesController.SearchInstances(targetKey, offset: 1, pageSize: 1);
            Debug.Assert(search6.TotalCount == 3);
            Debug.Assert(search6.Instances.Count() == 1);
            Debug.Assert(search6.Instances.ElementAt(0).Key == instance.Key);

            instancesController.DeleteInstance(aSecondInstance.Key);
            instancesController.DeleteInstance(zThirdInstance.Key);

            var searchDeleted = instancesController.SearchInstances(targetKey);
            Debug.Assert(searchDeleted.TotalCount == 1);
            Debug.Assert(searchDeleted.Instances.Count() == 1);
            Debug.Assert(searchDeleted.Instances.ElementAt(0).Key == instance.Key);
        }
        public ActionResult Delete(Guid id, FormCollection collection)
        {
            var instances = new Instances();
            var instance = instances.GetInstance(id);
            try
            {
                instances.DeleteInstance(id);

                return RedirectToAction("Index", new { tid = instance.TargetKey });
            }
            catch(Exception ex)
            {
                ModelState.AddModelError("Error", ex);
            }

            var targets = new Targets();
            var groups = new Groups();

            var target = targets.GetTarget(instance.TargetKey);
            var group = groups.GetGroup(target.GroupKey);

            var model = new InstanceDetails()
            {
                Instance = instance,
                Target = target,
                Group = group,
            };

            return View("ConfirmDelete", model);
        }