コード例 #1
0
        //
        // GET: /Instances/Create
        public ActionResult Create(Guid tid)
        {
            var targets = new Targets();
            var groups = new Groups();

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

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

            return View(model);
        }
コード例 #2
0
        //
        // GET: /Instances/ConfirmDelete/5
        public ActionResult ConfirmDelete(Guid id)
        {
            var instances = new Instances();
            var targets = new Targets();
            var groups = new Groups();

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

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

            return View(model);
        }
コード例 #3
0
        public ActionResult Create(Guid tid, string name)
        {
            var newInstance = new Instance()
            {
                Name = name,
                TargetKey = tid,
            };

            if (string.IsNullOrWhiteSpace(name)) ModelState.AddModelError("name", "Name is required.");

            if (ModelState.IsValid)
            {
                try
                {
                    var instances = new Instances();
                    instances.CreateInstance(newInstance);

                    return RedirectToAction("Details", new { id = newInstance.Key });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex);
                }
            }

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

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

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

            return View(model);
        }
コード例 #4
0
        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);
        }