Пример #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);
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #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));
        }
Пример #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);
        }
Пример #8
0
        public ActionResult formSubmit(RetrieveRole model, string actionType)
        {
            List <string> errorMessage   = new List <string>();
            string        successMessage = Resources.NotifResource.SecurityRoleSuccess;

            SecurityRole securityRole = new SecurityRole();

            securityRole.Name           = model.role.Name;
            securityRole.SecurityRoleId = model.role.SecurityRoleId;

            KeyValuePair <int, string> results = new KeyValuePair <int, string>(1, "");

            if (actionType == "Create")
            {
                //Check if there is already role with the same name
                int compareRoleName = db.securityRole.Where(x => x.Name == model.role.Name).Count();
                if (compareRoleName > 0)
                {
                    var jsonData = new { flag = false, Message = "Security role tidak boleh sama" };
                    return(Json(jsonData));
                }

                securityRole.BusinessUnitId    = model.role.BusinessUnitId;
                securityRole.CreatedOn         = DateTime.Now;
                securityRole.CreatedBy         = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString());
                securityRole.DeletionStateCode = 0;
                securityRole.Status            = 0;
                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);
                securityRole.XMLRole           = ParseXMLHelper.SerializeXml(model.xmlRole);

                db.securityRole.Add(securityRole);
                db.SaveChanges();

                results = new KeyValuePair <int, string>(0, "Role berhasil ditambahkan");
            }
            else if (actionType == "Edit")
            {
                securityRole.ModifiedOn       = DateTime.Now;
                securityRole.ModifiedBy       = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString());
                securityRole.BusinessUnitId   = model.role.BusinessUnitId;
                securityRole.XMLRole          = ParseXMLHelper.SerializeXml(model.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);

                securityRole.DeletionStateCode = model.role.DeletionStateCode;
                securityRole.Status            = model.role.Status;
                securityRole.CreatedBy         = model.role.CreatedBy;
                securityRole.CreatedOn         = model.role.CreatedOn;

                db.Entry(securityRole).State = EntityState.Modified;
                db.SaveChanges();

                results = new KeyValuePair <int, string>(0, "Role berhasil diupdate");
            }
            //else if (actionType == "Delete")
            //{
            //    //rcm.ModifiedBy_ID = new Guid(Session["CurrentUserID"].ToString());
            //    //results = sp.RequestCreationMatrix_Delete(rcm);
            //}

            if (results.Key == 0 || results.Key == 16 || results.Key == 6)
            {
                UrlHelper u      = new UrlHelper(this.ControllerContext.RequestContext);
                string    url    = u.Action("Edit", "SecurityRole", new { id = securityRole.SecurityRoleId, success = successMessage });
                string    urlNew = u.Action("Create", "SecurityRole");

                var jsonData = new { flag = true, Message = url, urlNew = urlNew };
                return(Json(jsonData));
            }
            else
            {
                var jsonData = new { flag = false, Message = results.Value.ToString() };
                return(Json(jsonData));
            }
        }