示例#1
0
 public ActionResult Delete(int?id, FormCollection collection)
 {
     try
     {
         PermissionDataRepository ml = new PermissionDataRepository();
         if (id != null && id > 0)
         {
             ml.Delete(id ?? 0);
         }
         else
         {
             if (string.IsNullOrEmpty(collection["IDs"]))
             {
                 return(Content("未指定删除对象ID"));
             }
             string[] ids = collection["IDs"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
             foreach (string item in ids)
             {
                 ml.Delete(int.Parse(item));
             }
         }
         return(Content("1"));
     }
     catch (Exception ex)
     {
         return(Content(ErrorWirter(RouteData, ex.Message)));
     }
 }
示例#2
0
        public ActionResult Edit(int id)
        {
            try
            {
                PermissionDataRepository ml = new PermissionDataRepository();

                PermissionData obj = ml.GetPermissionData(id);

                return(View(obj));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }
示例#3
0
        public ActionResult Create(FormCollection formCollection)
        {
            try
            {
                PermissionDataRepository ml = new PermissionDataRepository();

                PermissionData obj = new PermissionData()
                {
                    CreateDate = DateTime.Now, CreateUserID = ID, IsDeleted = false
                };

                UpdateModel(obj);

                bool result = ml.Insert(obj) > 0 ? true : false;

                return(result ? Content(ContentIcon.Succeed + "|操作成功|/Admin/PermissionData/Index") : Content(ContentIcon.Error + "|操作失败"));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }
示例#4
0
        public ActionResult Index(int?pageIndex, int?pageSize, PermissionMap entity)
        {
            try
            {
                PermissionMapRepository ml = new PermissionMapRepository();
                entity.IsDeleted = false;
                PagedList <PermissionMap> page = ml.Search(entity).GetPagedList(pageIndex ?? PageIndex, pageSize ?? PageSize, Order, By);
                if (page != null && page.TotalItemCount > 0)
                {
                    foreach (var item in page)
                    {
                        if (item.Menu.ID == 0)
                        {
                            PermissionDataRepository pl = new PermissionDataRepository();
                            var plts = pl.Search().Where(b => b.PID == item.ID).ToList();
                            if (plts != null)
                            {
                                pl.Deletes(plts);
                            }
                            ml.Delete(item);
                        }
                    }
                    page = ml.Search(entity).GetPagedList(pageIndex ?? PageIndex, pageSize ?? PageSize, Order, By);
                }
                IList <PermissionMap> objs = page;

                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Index", objs));
                }

                return(View(objs));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }
示例#5
0
        public ActionResult Edit(int id, FormCollection formCollection)
        {
            try
            {
                PermissionDataRepository ml = new PermissionDataRepository();

                PermissionData obj = ml.GetPermissionData(id);

                UpdateModel(obj);

                obj.LastUpdateDate = DateTime.Now;

                obj.LastUpdateUserID = ID;

                bool result = ml.Update(obj) > 0 ? true : false;

                return(result ? Content(ContentIcon.Succeed + "|操作成功") : Content(ContentIcon.Error + "|操作失败"));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }
示例#6
0
        public ActionResult Index(int?pageIndex, int?pageSize, PermissionData entity)
        {
            try
            {
                PermissionDataRepository ml = new PermissionDataRepository();

                entity.IsDeleted = false;

                PagedList <PermissionData> page = ml.Search(entity).GetPagedList(pageIndex ?? PageIndex, pageSize ?? PageSize, Order, By);

                IList <PermissionData> objs = page;

                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Index", objs));
                }

                return(View(objs));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }
        /// <summary>
        /// 更新文件(非阻塞方式)
        /// </summary>
        /// <returns></returns>
        public bool Write()
        {
            bool result = false;

            if (site.IsFromFile == true)
            {
                var application = System.Web.HttpContext.Current.Application;
                application.Lock();
                Init();
                try
                {
                    Thread mt = new Thread(new ThreadStart(() =>
                    {
                        var mlts = new MenuRepository().Search().Where(b => b.IsDeleted == false).ToList();
                        if (mlts != null)
                        {
                            _Menus          = mlts;
                            string menusStr = Common.JsonHelper.JsonSerializer <List <Menu> >(mlts);
                            menusStr        = Common.EncryptionHelper.AESHelper.Encrypt(menusStr, password);
                            string menuFile = menuFilePath + "Menu.html";
                            Common.FileHelper.DeleteFile(menuFile);
                            Common.FileHelper.WriteFile(menuFile, menusStr);
                        }
                    }));
                    Thread pmt = new Thread(new ThreadStart(() =>
                    {
                        var pmlts = new PermissionMapRepository().Search().Where(b => b.IsDeleted == false).ToList();
                        if (pmlts != null)
                        {
                            _PermissionMaps          = pmlts;
                            string permissionmapsStr = Common.JsonHelper.JsonSerializer <List <PermissionMap> >(pmlts);
                            permissionmapsStr        = Common.EncryptionHelper.AESHelper.Encrypt(permissionmapsStr, password);
                            string permissionmapFile = permissionMapFilePath + "PermissionMap.html";
                            Common.FileHelper.DeleteFile(permissionmapFile);
                            Common.FileHelper.WriteFile(permissionmapFile, permissionmapsStr);
                        }
                    }));
                    Thread pdt = new Thread(new ThreadStart(() =>
                    {
                        var pdlts = new PermissionDataRepository().Search().Where(b => b.IsDeleted == false).ToList();
                        if (pdlts != null)
                        {
                            _PermissionDatas          = pdlts;
                            string permissiondatasStr = Common.JsonHelper.JsonSerializer <List <PermissionData> >(pdlts);
                            permissiondatasStr        = Common.EncryptionHelper.AESHelper.Encrypt(permissiondatasStr, password);
                            string permissiondataFile = permissionDataFilePath + "PermissionData.html";
                            Common.FileHelper.DeleteFile(permissiondataFile);
                            Common.FileHelper.WriteFile(permissiondataFile, permissiondatasStr);
                        }
                    }));
                    mt.Start();
                    pmt.Start();
                    pdt.Start();
                    while (true)
                    {
                        if (mt.ThreadState == ThreadState.Stopped && pmt.ThreadState == ThreadState.Stopped && pdt.ThreadState == ThreadState.Stopped)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                    result = true;
                }
                catch { }
                application.UnLock();
            }
            return(result);
        }
示例#8
0
        public ActionResult Create(int[] kids, FormCollection formCollection)
        {
            try
            {
                RoleRepository ml = new RoleRepository();

                Role obj = new Role()
                {
                    CreateDate = DateTime.Now, CreateUserID = ID, IsDeleted = false
                };

                UpdateModel(obj);

                ml.Insert(obj);

                int rid = ml.Search(obj).First().ID;

                #region 更新引角色权限
                if (rid > 1)
                {
                    var pdl = new PermissionDataRepository();
                    pdl.DeleteByMIDOrRID(rid, 0);
                    var pmlts = new PermissionMapRepository().GetList(1, 1000);
                    if (pmlts != null)
                    {
                        string pData = formCollection["pData"];
                        foreach (var item in pmlts)
                        {
                            var pdt = new PermissionData()
                            {
                                PID              = item.ID,
                                RID              = rid,
                                HasPermission    = false,
                                CreateUserID     = CurrentMember.ID,
                                LastUpdateUserID = CurrentMember.ID,
                                CreateDate       = DateTime.Now,
                                LastUpdateDate   = DateTime.Now,
                                IsDeleted        = false
                            };
                            if (!string.IsNullOrEmpty(pData))
                            {
                                try
                                {
                                    var pDataArr = pData.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (pDataArr.Contains(item.ID.ToString()))
                                    {
                                        pdt.HasPermission = true;
                                    }
                                }
                                catch { }
                            }
                            pdl.Insert(pdt);
                        }
                    }
                }
                PermissionHelper permission = new PermissionHelper();
                permission.Write();
                #endregion

                return(Content(ContentIcon.Succeed + "|保存成功|/admin/Role/Index"));
            }
            catch (Exception ex)
            {
                return(Content(ContentIcon.Error + "|" + ErrorWirter(RouteData, ex.Message)));
            }
        }