public ActionResult Add()
        {
            ActionAddModel viewmodel = new ActionAddModel();

            if (TempData["HintMessage"] != null)
            {
                ViewData["HintMessage"] = TempData["HintMessage"];
            }
            if (TempData["InvalidModel"] != null && TempData["BrokenRules"] != null)
            {
                viewmodel.Function = TempData["InvalidModel"] as Function;
            }

            //2010-12-06 by huncherby 所属模块
            ViewData["Modules"] = RepositoryFactory.GetRepository<IModuleRepository, Module>().
                FindAll().ToSelectList<Module>(m => m.Name, m => m.Key.ToString());

            return View(viewmodel);
        }
        public ActionResult Edit(int? id)
        {
            ActionAddModel viewmodel = new ActionAddModel();

            if (TempData["HintMessage"] != null)
            {
                ViewData["HintMessage"] = TempData["HintMessage"];
            }
            if (TempData["InvalidModel"] != null && TempData["BrokenRules"] != null)
            {
                viewmodel.Function = TempData["InvalidModel"] as Function;
            }

            if (viewmodel.Function == null)
            {
                viewmodel.Function = this.repository.FindBy(id);

                 if (viewmodel.Function == null)
                    throw new HttpException(404, "无法找到相关的功能!");
            }

            string moduleid = null;
            StringBuilder sb = new StringBuilder();
            sb.Append("select b.id from function a,module b where a.moduleid=b.id and a.functionid='" + id + "'");
            DataTable dt = RepositoryFactory.GetRepository<IPipeTypeRepository, PipeType>().ExcuteDs(sb.ToString());
            moduleid = dt.Rows[0]["id"].ToString() == null ? null : dt.Rows[0]["id"].ToString();
            //2010-12-06 by huncherby 所属模块
            ViewData["Modules"] = RepositoryFactory.GetRepository<IModuleRepository, Module>().FindAll().ToSelectList<Module>(m => m.Name, m => m.Key.ToString(),moduleid);

            return this.View(viewmodel);
        }
        public ActionResult Update(ActionAddModel model)
        {
            if (model == null || model.Function == null)
                throw new HttpException(404, "系统发生一个错误!");

            Function action = model.Function;

            ReadOnlyCollection<BrokenRule> brokenRules = action.GetBrokenRules();

            if (brokenRules.Count == 0)
            {
                //功能模块action修改 2011-5-20 by huncherby
                string moduleid = action.Module.Key.ToString();
                string controller = action.Controller;
                string actionno = action.Action;
                string name = action.Name;
                string des = action.Description;
                int state = (int)action.Status;
                string key=action.Key.ToString();

                StringBuilder sb = new StringBuilder();
                sb.Append("update function set name='"+name+"',moduleid='"+moduleid+"',controller='"+controller+"',action='"+actionno+"',Description='"+des+"',status="+state+" where functionid='"+key+"'");

                IBusinessCheckNoticeRepository bc = RepositoryFactory.GetRepository<IBusinessCheckNoticeRepository, BusinessCheckNotice>();
                bc.Excute(sb.ToString());
                //repository[action.Key] = action;
                //unitOfWork.Commit();

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("功能({0})修改成功", model.Function.Name) };

            }
            else
            {
                TempData["InvalidModel"] = model;
                TempData["BrokenRules"] = brokenRules;
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("人员({0})修改失败,请检查你的输入", model.Function.Name) };

            }

            return RedirectToAction("Edit", new { id = model.Function.Key });
        }
        public ActionResult Create(ActionAddModel model)
        {
            if (model == null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "操作失败,系统发生了一个错误" };
                return RedirectToAction("Add");
            }

            ReadOnlyCollection<BrokenRule> brokenRules = model.Function.GetBrokenRules();

            if (brokenRules.Count == 0)
            {
                repository.Add(model.Function);
                unitOfWork.Commit();
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("功能({0})添加成功", model.Function.Name) };
            }
            else
            {
                TempData["InvalidModel"] = model;
                TempData["BrokenRules"] = brokenRules;
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("人员({0})修改失败,请检查你的输入", model.Function.Name) };
            }

            return RedirectToAction("Index", "Block" /*, new { id = model.Function.Module.Key } */);
        }