public ActionResult Create(Guid gid)
        {
            var groups = new Groups();
            var group = groups.GetGroup(gid);

            var model = new TargetDetails()
            {
                Target = new Target() { GroupKey = gid },
                Group = group,
            };

            return View(model);
        }
        public ActionResult ConfirmDelete(Guid id)
        {
            var targets = new Targets();
            var groups = new Groups();

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

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

            return View(model);
        }
        public ActionResult Create(Guid gid, string name)
        {
            var newTarget = new Target()
            {
                GroupKey = gid,
                Name = name,
            };

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

            if (ModelState.IsValid)
            {
                try
                {
                    var targets = new Targets();
                    targets.CreateTarget(newTarget);
                    try
                    {
                        var defaultAppValue = System.Configuration.ConfigurationManager.AppSettings["Plywood.DefaultApp"];
                        if (!string.IsNullOrEmpty(defaultAppValue))
                        {
                            Guid defaultApp;
                            if (Guid.TryParse(defaultAppValue, out defaultApp))
                            {
                                var targetApps = new TargetApps();
                                targetApps.AddApp(newTarget.Key, defaultApp);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // TODO: Log failing to add the toolkit to a new target.
                        // Just carry on - this isn't too important!
                    }
                    return RedirectToAction("Details", new { id = newTarget.Key });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex);
                }
            }

            var groups = new Groups();
            var group = groups.GetGroup(gid);

            var model = new TargetDetails()
            {
                Target = new Target() { GroupKey = gid },
                Group = group,
            };

            return View(model);
        }
        public ActionResult Edit(Guid id, string name)
        {
            Target target = null;
            try
            {
                var targets = new Targets();
                target = targets.GetTarget(id);
                target.Name = name;
                targets.UpdateTarget(target);
                return RedirectToAction("Details", new { id = target.Key });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex);
            }

            var groups = new Groups();
            Group group = null;
            if (target != null)
                group = groups.GetGroup(target.GroupKey);

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

            return View(model);
        }
        public ActionResult Delete(Guid id)
        {
            var targets = new Targets();
            var target = targets.GetTarget(id);
            try
            {
                targets.DeleteTarget(id);
                return RedirectToAction("Index", new { gid = target.GroupKey });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);

                var groups = new Groups();
                var group = groups.GetGroup(target.GroupKey);

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

                return View("ConfirmDelete", model);
            }
        }