Exemplo n.º 1
0
        public ActionResult Install(int[] Id, int[] ParentId, string[] Title, string[] URL, string[] Code, string[] Icon, string[] IsMenuItem, string[] IsUsed)
        {
            try
            {
                DataTable Permissions = new DataTable();
                Permissions.Columns.AddRange(new DataColumn[8]
                {
                    new DataColumn("Id", typeof(int)),
                    new DataColumn("ParentId", typeof(int)),
                    new DataColumn("Title", typeof(string)),
                    new DataColumn("URL", typeof(string)),
                    new DataColumn("Code", typeof(string)),
                    new DataColumn("Icon", typeof(string)),
                    new DataColumn("IsMenuItem", typeof(bool)),
                    new DataColumn("IsUsed", typeof(bool)),
                });

                for (int i = 0; i < Id.Length; i++)
                {
                    DataRow row;
                    row               = Permissions.NewRow();
                    row["Id"]         = Id[i];
                    row["ParentId"]   = ParentId[i];
                    row["Title"]      = Title[i];
                    row["URL"]        = URL[i];
                    row["Code"]       = Code[i];
                    row["Icon"]       = Icon[i];
                    row["IsMenuItem"] = (IsMenuItem.Contains("mnu-" + Id[i])) == true ? true : false;
                    if (IsUsed != null)
                    {
                        row["IsUsed"] = (IsUsed.Contains("no-" + Id[i])) == true ? false : true;
                    }

                    Permissions.Rows.Add(row);
                }

                Sec_PermissionDL pd = new Sec_PermissionDL();
                pd.Save(Permissions);
                TempData["msg_success"] = "Save successfully";
            }
            catch (Exception ex)
            {
                TempData["msg_error"] = ex.Message;
            }



            return(RedirectToAction("all"));
        }
Exemplo n.º 2
0
        private bool InsertPermissions(string Module, string Namespace)
        {
            List <string> Controllers = new List <string>();

            Controllers = GetControllers(Namespace);


            DataTable Permissions = new DataTable();

            Permissions.Columns.AddRange(new DataColumn[6]
            {
                new DataColumn("Id", typeof(int)),
                new DataColumn("ParentId", typeof(int)),
                new DataColumn("Title", typeof(string)),
                new DataColumn("URL", typeof(string)),
                new DataColumn("Code", typeof(string)),
                new DataColumn("In_menu", typeof(bool)),
            });
            Sec_PermissionBL pl = new Sec_PermissionBL();
            int Id = pl.GetLastId() + 1;
            int tempParentId = 0, ModuleId = 1;

            ModuleId = Id;


            PermissionDataRow(Permissions, Id, 0, Module, "#", null);


            foreach (string Cont in Controllers)
            {
                var  Actions = ActionNames(Cont);
                bool Menu    = true;
                if (p.InMenuExist(Cont))
                {
                    Menu = false;
                }

                if (Menu)
                {
                    Id++; tempParentId = Id;

                    if (Actions.Count > 1)
                    {
                        PermissionDataRow(Permissions, Id, ModuleId, Cont, "#", Cont.Substring(0, 3), Menu);
                        foreach (var Action in Actions)
                        {
                            Menu = true;
                            if (p.InMenuExist(Action))
                            {
                                Menu = false;
                            }
                            if (!p.DropActionExist(Action))
                            {
                                Id++;
                                string code = Cont.Substring(0, 3) + Action.Substring(0, 3);
                                PermissionDataRow(Permissions, Id, tempParentId, Cont + " " + Action, "/" + Cont + "/" + Action, code, Menu);
                            }
                        }
                    }
                    else
                    {
                        string code = Cont.Substring(0, 3) + Actions[0].Substring(0, 3);
                        PermissionDataRow(Permissions, Id, ModuleId, Cont, "/" + Cont + "/" + Actions[0], code, Menu);
                    }
                }
            }


            Sec_PermissionDL pd = new Sec_PermissionDL();

            return(pd.Save(Permissions));
        }