Beispiel #1
0
        //Get all actions list to from selected role and entityname
        public static List <RootMenuSubmenuEntityAction> getActionButton(Guid roleID, string entityName)
        {
            CRMDb db             = new CRMDb();
            var   getCurrentRole = db.securityRole.Find(roleID);
            Root  roleObject     = (Root)ParseXMLHelper.DeserializeXml(getCurrentRole.XMLRole, "db");;


            var ent =
                (
                    from menu in roleObject.Menu
                    from submenu in menu.Submenu
                    from entity in submenu.Entity
                    where entity.name == entityName && entity.Action != null

                    //where entity.name == entityName
                    //where action != null && action.check == true
                    select new RootMenuSubmenuEntity {
                Action = entity.Action
            }
                ).ToList();

            List <RootMenuSubmenuEntityAction> actionList = ent.SelectMany(x => x.Action).ToList();

            return(actionList);
        }
Beispiel #2
0
        //Get XML role for writing menu
        public static Root getRoleObject(Guid roleID)
        {
            CRMDb db             = new CRMDb();
            Root  roleObject     = new Root();
            var   getCurrentRole = db.securityRole.Find(roleID);

            roleObject = (Root)ParseXMLHelper.DeserializeXml(getCurrentRole.XMLRole, "db");;
            return(roleObject);
        }
Beispiel #3
0
        public ActionResult Create()
        {
            //ViewBag.BusinessUnit = new SelectList(db.businessunit, "BusinessUnitId", "Name");

            RetrieveRole model = new RetrieveRole();
            SecurityRole role  = new SecurityRole();

            model.role = role;
            Root xmlRoot = (Root)ParseXMLHelper.DeserializeXml(xmlPath, "file");

            model.xmlRole = xmlRoot;

            return(View(model));
        }
Beispiel #4
0
        //Check entity by roleid - used on call wrapup function
        public static bool isEntityChecked(Guid roleID, string entityName)
        {
            CRMDb db             = new CRMDb();
            var   getCurrentRole = db.securityRole.Find(roleID);
            Root  roleObject     = (Root)ParseXMLHelper.DeserializeXml(getCurrentRole.XMLRole, "db");;

            if (roleObject.Menu.Any(a => a.Submenu.Any(b => b.Entity.Any(c => c.name == entityName && c.check == true))))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        //Check action by roleid to decide when the button should be showed or hidden
        public static bool checkEntityButtonByRoleID(Guid roleID, string entityName, string action)
        {
            CRMDb db             = new CRMDb();
            var   getCurrentRole = db.securityRole.Find(roleID);
            Root  roleObject     = (Root)ParseXMLHelper.DeserializeXml(getCurrentRole.XMLRole, "db");;

            if (roleObject.Menu.Any(a => a.Submenu.Any(b => b.Entity.Any(c => c.name == entityName && c.Action != null))))
            {
                bool isCheck = roleObject.Menu.Any(a => a.Submenu.Any(b => b.Entity.Any(c => c.name == entityName && c.Action.Any(d => d.name == action && d.check == true))));
                return(isCheck);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        //Edit load xml from
        public ActionResult Edit(Guid Id)
        {
            ViewBag.BusinessUnit = new SelectList(db.businessunit, "BusinessUnitId", "Name");
            ViewBag.actionType   = "Edit";

            var getRoleDB = db.securityRole
                            .Where(x => x.SecurityRoleId == Id)
                            .FirstOrDefault();

            //Get xml from file
            Root rootFile = (Root)ParseXMLHelper.DeserializeXml(xmlPath, "file");
            //Get xml from DB
            Root rootDB = new Root();

            if (getRoleDB.XMLRole != null && getRoleDB.XMLRole != "")
            {
                rootDB = (Root)ParseXMLHelper.DeserializeXml(getRoleDB.XMLRole, "db");
            }

            Root rootResult = rootFile;

            RetrieveRole model = new RetrieveRole();

            model.role = getRoleDB;

            DateTime fileModified = DateTime.ParseExact(System.IO.File.GetLastWriteTime(Server.MapPath(xmlPath)).ToString("dd/MM/yyyy HH:mm:ss"), "dd/MM/yyyy HH:mm:ss", null);
            bool     isFileDBSame = fileModified == getRoleDB.FileModifiedDate;

            //If new table role empty get xml from file
            if (getRoleDB.FileModifiedDate == null && getRoleDB.XMLRole == null)
            {
            }
            //else if (isFileDBSame == true)
            //{
            //    rootResult = rootDB;
            //}
            //IF there are any new entities added to xml file then compare and add new entity and action to xml db string
            else //if (isFileDBSame == false)
            {
                rootResult = functionUpdateXML(rootFile, rootDB);
            }

            model.xmlRole = rootResult;

            return(View(model));
        }
Beispiel #7
0
        private bool UpdateXMLRole(SecurityRole entryRole)
        {
            bool  flag = false;
            CRMDb conn = new CRMDb();

            RetrieveRole retrieveRole = new RetrieveRole();

            //var role = db.securityRole.Find(SecurityRoleId);

            retrieveRole.role = entryRole;

            Root xmlFile = (Root)ParseXMLHelper.DeserializeXml(xmlPath, "file");

            Root dbFile = new Root();

            if (entryRole.XMLRole != null && entryRole.XMLRole != "")
            {
                dbFile = (Root)ParseXMLHelper.DeserializeXml(entryRole.XMLRole, "db");

                dbFile = functionUpdateXML(xmlFile, dbFile);
            }

            retrieveRole.xmlRole = dbFile;

            SecurityRole securityRole = conn.securityRole.Find(retrieveRole.role.SecurityRoleId);

            securityRole.ModifiedOn = DateTime.Now;
            securityRole.ModifiedBy = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString());
            //securityRole.BusinessUnitId = retrieveRole.role.BusinessUnitId;
            securityRole.XMLRole          = ParseXMLHelper.SerializeXml(retrieveRole.xmlRole);
            securityRole.FileModifiedDate = DateTime.ParseExact(System.IO.File.GetLastWriteTime(Server.MapPath(xmlPath)).ToString("dd/MM/yyyy HH:mm:ss"), "dd/MM/yyyy HH:mm:ss", null);

            conn.Entry(securityRole).State = EntityState.Modified;

            conn.SaveChanges();
            flag = true;

            return(flag);
        }