public ActionResult AddOrUpdateModules(FormCollection formCollection, ModulesContract modulesContract)
        {
            //验证通过
            if (ModelState.IsValid)
            {
                #region 定义变量

                //用于判断操作是否成功
                bool boo = false;
                //获取当前添加的节点归属(属于子节点还是父节点)
                string[] str;
                //一级菜单ID
                int numOne;
                //二级菜单ID
                int numTwo;
                //获取上传的名字
                string fileName = "";
                //设置文件上传的路径
                string savaPath = "";

                #endregion 定义变量

                #region 文件上传

                for (var i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase HttpPostedFileBase = Request.Files[i];
                    //设置文件上传的路径
                    savaPath = AppDomain.CurrentDomain.BaseDirectory + @"\Images\ModuleImage\";
                    //获取上传的名字
                    fileName = Path.GetFileName(HttpPostedFileBase.FileName);
                    if (HttpPostedFileBase != null && !string.IsNullOrEmpty(fileName))
                    {
                        //判断当前文件是否存在已经重名图片
                        string filePath = savaPath + fileName;
                        if (System.IO.File.Exists(filePath))
                        {
                            DateTime dateTime = DateTime.Now;
                            string[] strFile = fileName.Split('.');
                            StringBuilder SbString = new StringBuilder();
                            SbString.Append(strFile[0]);
                            SbString.Append(dateTime.Year.ToString());
                            SbString.Append(dateTime.Month.ToString());
                            SbString.Append(dateTime.Day.ToString());
                            SbString.Append(dateTime.Hour.ToString());
                            SbString.Append(dateTime.Minute.ToString());
                            SbString.Append(dateTime.Second.ToString());
                            SbString.Append(".");
                            SbString.Append(strFile[1]);
                            fileName = SbString.ToString();
                        }
                        HttpPostedFileBase.SaveAs(Path.Combine(savaPath, fileName));
                    }
                }

                #endregion 文件上传

                #region 菜单归属

                str = formCollection["ModuleMenuID"].Split(',');
                int.TryParse(str[0], out numOne);
                int.TryParse(str[1], out numTwo);
                if (numOne == 0)
                {
                    //一级菜单的ID为0说明当前添加的是根菜单
                    modulesContract.ModuleParentID = 0;
                }
                else
                {
                    //如果二级菜单是0说明当前添加的菜单归属于一级菜单,否则归属于二级菜单
                    modulesContract.ModuleParentID = numTwo == 0 ? numOne : numTwo;
                }

                #endregion 菜单归属

                //设置当前菜单图片名称
                modulesContract.ModuleIcon = fileName;
                //获取当前页面拥有的操作
                string authority = formCollection["ModuleAuthority"] == null ? "" : formCollection["ModuleAuthority"];
                //执行添加操作
                if (string.IsNullOrEmpty(formCollection["ModuleID"]))
                {
                    boo = modulesServices.InsertModules(modulesContract, authority);
                }
                //执行修改操作
                else
                {
                    boo = modulesServices.UpdateModules(modulesContract, authority);
                }
                if (boo)
                {
                    //执行成功信息
                    ViewData["msg"] = "更新菜单成功!";
                    //成功后要跳转的路径(如果无须跳转,直接留在当前页面,不写即可)
                    ViewData["url"] = new UrlHelper(Request.RequestContext).Action("ModuleList");
                    //成功视图
                    return View("Success");
                }
                else
                {
                    //执行失败信息
                    ViewData["msg"] = "更新菜单失败!";
                    return View("Error");
                }
            }

            //验证失败

            #region 判断默认菜单选项

            StringBuilder sbOneStr = new StringBuilder();
            StringBuilder sbTwoStr = new StringBuilder();
            sbOneStr.Append("<option value='0'>--请选择--</option>");
            sbTwoStr.Append("<option value='0'>--请选择--</option>");

            //获取所有的一级菜单
            List<ModulesContract> list = modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, 0);

            if (modulesContract.ModuleParentID == 0)
            {
                foreach (var item in list)
                {
                    sbOneStr.Append(string.Format("<option  value={0}>{1}</option>", item.ModuleID, item.ModuleName));
                }

                ViewData["OneMenu"] = sbOneStr.ToString();

                ViewData["TwoMenu"] = sbTwoStr.ToString();
            }

            else
            {
                //判断当前节点是否是3级菜单(当前菜单的父级信息的ModuleParentID!=0则当前菜单为3级菜单)
                ModulesContract modules_One_Entity = modulesServices.GetModuleEntity(modulesContract.ModuleParentID.ToString());
                if (modules_One_Entity.ModuleParentID != 0)
                {
                    foreach (var item in list)
                    {
                        sbOneStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleParentID ? "selected" : "", item.ModuleID, item.ModuleName));
                    }

                    ViewData["OneMenu"] = sbOneStr.ToString();

                    //循环二级菜单
                    foreach (var item in modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, modules_One_Entity.ModuleParentID))
                    {
                        sbTwoStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleID ? "selected" : "", item.ModuleID, item.ModuleName));
                    }

                    ViewData["TwoMenu"] = sbTwoStr.ToString();
                }
                else
                {
                    foreach (var item in list)
                    {
                        sbOneStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleID ? "selected" : "", item.ModuleID, item.ModuleName));
                    }
                    ViewData["OneMenu"] = sbOneStr.ToString();
                    //循环二级菜单
                    foreach (var item in modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, modules_One_Entity.ModuleID))
                    {
                        sbTwoStr.Append(string.Format("<option  value={0}>{1}</option>", item.ModuleID, item.ModuleName));
                    }
                    ViewData["TwoMenu"] = sbTwoStr.ToString();
                }
            }

            #endregion 判断默认菜单选项

            ViewData["ModulesType"] = new SelectList(moduleTypeService.GetAllModuleType(), "ModuleTypeID", "ModuleTypeName");
            ViewData["Authority"] = authorityServices.GetAllAuthority();
            //页面拥有的功能
            ViewData["Module_Authority"] = moduleAuthorityListServices.GetAuthorityByModuleID(modulesContract.ModuleID);
            return View(modulesContract);
        }
 /// <summary>
 /// 更新数据(执行的存储过程)
 /// </summary>
 /// <param name="modules"></param>
 /// <param name="authorityStr"></param>
 /// <returns></returns>
 public bool UpdateModules(ModulesContract modulesContract, string authorityStr)
 {
     Modules modules = modulesContract.ToPO<Modules>();
     return modulesRepository.UpdateModules(modules: modules, authorityStr: authorityStr);
 }
        /// <summary>
        /// 更新或者添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult AddOrUpdateModules(string actionTag, string id)
        {
            ModulesContract modulesContract = new ModulesContract();

            //用于查询当前菜单拥有的功能点
            int moduleId;
            int.TryParse(id, out moduleId);
            //判断为更新页面
            if (!"add".Equals(actionTag))
            {
                modulesContract = modulesServices.GetModuleEntity(id);

                #region 判断默认菜单选项

                StringBuilder sbOneStr = new StringBuilder();
                StringBuilder sbTwoStr = new StringBuilder();
                sbOneStr.Append("<option value='0'>--请选择--</option>");
                sbTwoStr.Append("<option value='0'>--请选择--</option>");
                //获取所有的一级菜单
                List<ModulesContract> list = modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, 0);
                if (modulesContract.ModuleParentID == 0)
                {
                    foreach (var item in list)
                    {
                        sbOneStr.Append(string.Format("<option  value={0}>{1}</option>", item.ModuleID, item.ModuleName));
                    }
                    ViewData["OneMenu"] = sbOneStr.ToString();
                    ViewData["TwoMenu"] = sbTwoStr.ToString();
                }
                else
                {
                    //判断当前节点是否是3级菜单(当前菜单的父级信息的ModuleParentID!=0则当前菜单为3级菜单)
                    ModulesContract modules_One_Entity = modulesServices.GetModuleEntity(modulesContract.ModuleParentID.ToString());
                    if (modules_One_Entity.ModuleParentID != 0)
                    {
                        foreach (var item in list)
                        {
                            sbOneStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleParentID ? "selected" : "", item.ModuleID, item.ModuleName));
                        }
                        ViewData["OneMenu"] = sbOneStr.ToString();
                        //循环二级菜单
                        foreach (var item in modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, modules_One_Entity.ModuleParentID))
                        {
                            sbTwoStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleID ? "selected" : "", item.ModuleID, item.ModuleName));
                        }
                        ViewData["TwoMenu"] = sbTwoStr.ToString();
                    }
                    else
                    {
                        foreach (var item in list)
                        {
                            sbOneStr.Append(string.Format("<option {0} value={1}>{2}</option>", item.ModuleID == modules_One_Entity.ModuleID ? "selected" : "", item.ModuleID, item.ModuleName));
                        }
                        ViewData["OneMenu"] = sbOneStr.ToString();
                        //循环二级菜单
                        foreach (var item in modulesServices.GetModulesByIdAndTypeId(modulesContract.ModuleTypeID, modules_One_Entity.ModuleID))
                        {
                            sbTwoStr.Append(string.Format("<option  value={0}>{1}</option>", item.ModuleID, item.ModuleName));
                        }
                        ViewData["TwoMenu"] = sbTwoStr.ToString();
                    }
                }

                #endregion 判断默认菜单选项
            }
            //页面拥有的功能点
            ViewData["Module_Authority"] = moduleAuthorityListServices.GetAuthorityByModuleID(moduleId);
            //查询菜单类型
            ViewData["ModulesType"] = new SelectList(moduleTypeService.GetAllModuleType(), "ModuleTypeID", "ModuleTypeName", modulesContract.ModuleTypeID);
            //页面功能(所有功能点)
            ViewData["Authority"] = authorityServices.GetAllAuthority();
            //返回视图
            return View(modulesContract);
        }