예제 #1
0
        public ActionResult Create(Crawler.Entity.TaskItem item, string createAddCaptureRule, string captureRuleForContent, string captureRuleForNavigation)
        {
            if (ModelState.IsValid)
            {
                item.ID = Guid.NewGuid();

                if (!string.IsNullOrEmpty(captureRuleForContent))
                {
                    Crawler.Entity.CaptureRule captureRuleCon = new Crawler.Entity.CaptureRule { ID = new Guid(captureRuleForContent) };
                    captureRuleService.Context.Set<Crawler.Entity.CaptureRule>().Attach(captureRuleCon);
                    item.CaptureRules.Add(captureRuleCon);
                }
                if (!string.IsNullOrEmpty(captureRuleForNavigation))
                {
                    CaptureRule captureRuleNav = new CaptureRule { ID = new Guid(captureRuleForNavigation) };
                    captureRuleService.Context.Set<CaptureRule>().Attach(captureRuleNav);
                    item.CaptureRules.Add(captureRuleNav);
                }

                taskItemService.Create(item);
                if (string.IsNullOrEmpty(createAddCaptureRule))
                {
                    return RedirectToAction("Index", new { taskid = item.TaskId });
                }
                else
                {
                    return RedirectToAction("Create", "CaptureRule", new { taskitemid = item.ID });
                }

            }

            ViewBag.TaskId = new SelectList(taskService.GetAll(), "ID", "Name", item.TaskId);
            ViewBag.PageCategory = new SelectList(DictionaryDataUtil.GetData("pageType"), "ID", "Name", 1);
            return View(item);
        }
예제 #2
0
        public ActionResult Create(string taskitemid, string captureRuleId, CaptureRule captureRule)
        {
            TaskItem item = new TaskItem { ID = new Guid(taskitemid) };
            taskItemService.Context.Set<TaskItem>().Attach(item);

            if (!String.IsNullOrEmpty(captureRuleId))
            {
                ////TaskItem item = new TaskItem { ID = new Guid( taskitemid)};
                ////TaskItem item = rule.TaskItems.SingleOrDefault(i => i.ID == new Guid(taskitemid));

                //CaptureRule rule = new CaptureRule {ID = new Guid( captureRuleId)};
                //rule.TaskItems = new HashSet<TaskItem> { new TaskItem { ID = new Guid( taskitemid)} };
                //captureRuleService.Context.Set<CaptureRule, Guid>().Attach(rule);
                //captureRuleService.Context.Entry<CaptureRule, Guid>().State = System.Data.EntityState.

                //CaptureRule rule = item.CaptureRules.SingleOrDefault(c => c.ID == new Guid(captureRuleId));
                captureRule = new CaptureRule { ID = new Guid(captureRuleId) };
                captureRuleService.Context.Set<CaptureRule>().Attach(captureRule);
            }
            else
            {
                captureRule.ID = Guid.NewGuid();
            }
            if (ModelState.IsValid)
            {

                item.CaptureRules.Add(captureRule);

                //captureRuleService.Create(rule);
                taskItemService.Context.SaveChanges();
                return RedirectToAction("Index");
            }
            //try
            //{
            //    // TODO: Add insert logic here

            //    return RedirectToAction("Index");
            //}
            //catch
            //{
            //    return View();
            //}

            SetData(taskitemid);
            return View();
        }