コード例 #1
0
        public ActionResult AddTag(Guid id, string name, string value)
        {
            var targets = new Targets();
            var target = targets.GetTarget(id);
            if (target.Tags.ContainsKey(name))
                throw new HttpException(406, "Tag name already exists");

            target.Tags.Add(name, value);
            targets.UpdateTarget(target);
            if (Request.IsAjaxRequest())
                return Json(null);
            else
                return RedirectToAction("EditTags", new { id = id });
        }
コード例 #2
0
        public JsonResult UpdateTag(Guid id, string oldName, string name, string value)
        {
            var targets = new Targets();
            var target = targets.GetTarget(id);
            if (!target.Tags.ContainsKey(oldName))
                throw new HttpException(404, "Tag not found");

            if (oldName == name)
            {
                target.Tags[name] = value;
            }
            else if (target.Tags.ContainsKey(name))
            {
                throw new HttpException(406, "Tag name already exists");
            }
            else
            {
                target.Tags.Remove(oldName);
                target.Tags.Add(name, value);
            }
            targets.UpdateTarget(target);
            return Json(null);
        }
コード例 #3
0
        public JsonResult RemoveTag(Guid id, string name)
        {
            var targets = new Targets();
            var target = targets.GetTarget(id);
            if (!target.Tags.ContainsKey(name))
                throw new HttpException(404, "Tag not found");

            target.Tags.Remove(name);
            targets.UpdateTarget(target);
            return Json(null);
        }
コード例 #4
0
        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);
        }