Пример #1
0
        public JsonResult UpdatePageAction(int id, List <Models.RolePageModel> model)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            IDAL.IAdminToPageRepository repository = EnterRepository.GetRepositoryEnter().GetAdminToPageRepository;
            foreach (var item in model)
            {
                AuthorDesign.Model.AdminToPage authoryPageModel = repository.LoadEntities(m => m.AdminId == id && m.PageId == item.PageId).FirstOrDefault();
                if (authoryPageModel == null)
                {
                    authoryPageModel            = new Model.AdminToPage();
                    authoryPageModel.AdminId    = id;
                    authoryPageModel.PageId     = item.PageId;
                    authoryPageModel.ActionList = serializer.Serialize(item.ActionList);
                    if (item.ActionList != null && item.ActionList.Count() > 0)
                    {
                        if (item.ActionList.Where(m => m.actionChecked == 1).Count() == 0)
                        {
                            authoryPageModel.IsShow = (byte)0;
                        }
                        else
                        {
                            authoryPageModel.IsShow = (byte)1;
                        }
                    }
                    else
                    {
                        authoryPageModel.IsShow = (byte)0;
                    }
                    repository.AddEntity(authoryPageModel);
                }
                else
                {
                    authoryPageModel.AdminId    = id;
                    authoryPageModel.PageId     = item.PageId;
                    authoryPageModel.ActionList = serializer.Serialize(item.ActionList);
                    if (item.ActionList != null && item.ActionList.Count() > 0)
                    {
                        if (item.ActionList.Where(m => m.actionChecked == 1).Count() == 0)
                        {
                            authoryPageModel.IsShow = (byte)0;
                        }
                        else
                        {
                            authoryPageModel.IsShow = (byte)1;
                        }
                    }
                    else
                    {
                        authoryPageModel.IsShow = (byte)0;
                    }
                }
            }
            PublicFunction.AddOperation(2, string.Format("编辑管理员页面按钮"), string.Format("编辑管理员页面按钮成功"));
            if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
            {
                return(Json(new { state = "success", message = "编辑管理员页面按钮成功" }));
            }
            else
            {
                PublicFunction.AddOperation(2, string.Format("编辑角色页面按钮"), string.Format("编辑角色页面按钮失败"));
                EnterRepository.GetRepositoryEnter().SaveChange();
                return(Json(new { state = "fail", message = "编辑管理员页面按钮失败" }));
            }
        }
 public JsonResult UpdatePageAction(int id, List<Models.RolePageModel> model)
 {
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     IDAL.IAdminToPageRepository repository = EnterRepository.GetRepositoryEnter().GetAdminToPageRepository;
     foreach (var item in model) {
         AuthorDesign.Model.AdminToPage authoryPageModel = repository.LoadEntities(m => m.AdminId == id && m.PageId == item.PageId).FirstOrDefault();
         if (authoryPageModel == null) {
             authoryPageModel = new Model.AdminToPage();
             authoryPageModel.AdminId = id;
             authoryPageModel.PageId = item.PageId;
             authoryPageModel.ActionList = serializer.Serialize(item.ActionList);
             if (item.ActionList != null && item.ActionList.Count() > 0) {
                 if (item.ActionList.Where(m => m.actionChecked == 1).Count() == 0) {
                     authoryPageModel.IsShow = (byte)0;
                 }
                 else {
                     authoryPageModel.IsShow = (byte)1;
                 }
             }
             else {
                 authoryPageModel.IsShow = (byte)0;
             }
             repository.AddEntity(authoryPageModel);
         }
         else {
             authoryPageModel.AdminId = id;
             authoryPageModel.PageId = item.PageId;
             authoryPageModel.ActionList = serializer.Serialize(item.ActionList);
             if (item.ActionList != null && item.ActionList.Count() > 0) {
                 if (item.ActionList.Where(m => m.actionChecked == 1).Count() == 0) {
                     authoryPageModel.IsShow = (byte)0;
                 }
                 else {
                     authoryPageModel.IsShow = (byte)1;
                 }
             }
             else {
                 authoryPageModel.IsShow = (byte)0;
             }
         }
     }
     PublicFunction.AddOperation(2, string.Format("编辑管理员页面按钮"), string.Format("编辑管理员页面按钮成功"));
     if (EnterRepository.GetRepositoryEnter().SaveChange() > 0) {
         CacheHelper.RemoveCache("AdminMenuList");
         return Json(new { state = "success", message = "编辑管理员页面按钮成功" });
     }
     else {
         PublicFunction.AddOperation(2, string.Format("编辑角色页面按钮"), string.Format("编辑角色页面按钮失败"));
         EnterRepository.GetRepositoryEnter().SaveChange();
         return Json(new { state = "fail", message = "编辑管理员页面按钮失败" });
     }
 }