Exemplo n.º 1
0
        private bool SaveRoleForPermission(string oldrolename, string newrolename)
        {
            List <SEC_ROLE_OBJECT_PERMISSION> lstpermission = null;
            List <SEC_ROLE_OBJECT_PERMISSION> newpermission = new List <SEC_ROLE_OBJECT_PERMISSION>();
            SEC_ROLE_OBJECT_PERMISSION        permission;
            bool insert = false;
            bool submit = false;

            // bool update = false;
            try
            {
                lstpermission = (from dspermission in DB.SEC_ROLE_OBJECT_PERMISSION.AsEnumerable()
                                 where dspermission.ROLE_NAME.ToUpper() == oldrolename.Trim().ToUpper()
                                 select dspermission).ToList <SEC_ROLE_OBJECT_PERMISSION>();
                foreach (SEC_ROLE_OBJECT_PERMISSION roleperm in lstpermission)
                {
                    permission              = new SEC_ROLE_OBJECT_PERMISSION();
                    permission.ROWID        = Guid.NewGuid();
                    permission.ROLE_NAME    = newrolename;
                    permission.DELETE_FLAG  = false;
                    permission.ENTERED_DATE = serverDate;
                    permission.ENTERED_BY   = userInformation.UserName;
                    permission.OBJECT_NAME  = roleperm.OBJECT_NAME;
                    permission.PERM_ADD     = roleperm.PERM_ADD;
                    permission.PERM_DELETE  = roleperm.PERM_DELETE;
                    permission.PERM_EDIT    = roleperm.PERM_EDIT;
                    permission.PERM_PRINT   = roleperm.PERM_PRINT;
                    permission.PERM_VIEW    = roleperm.PERM_VIEW;
                    permission.PERM_SHOW    = roleperm.PERM_SHOW;
                    newpermission.Add(permission);
                }
                insert = true;
                if (newpermission.Count > 0)
                {
                    DB.SEC_ROLE_OBJECT_PERMISSION.DeleteAllOnSubmit(lstpermission);
                }
                DB.SEC_ROLE_OBJECT_PERMISSION.InsertAllOnSubmit(newpermission);
                submit = true;
                DB.SubmitChanges();
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);

                return(false);
            }
            catch (Exception ex)
            {
                ex.LogException();
                if (submit == true)
                {
                    if (insert == true)
                    {
                        DB.SEC_ROLE_OBJECT_PERMISSION.DeleteAllOnSubmit(newpermission);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert default permission for the role
        /// </summary>
        /// <param name="rolename"></param>
        /// <returns>boolean</returns>
        private bool InsertDefaultPermissionForRole(string rolename, ref List <SEC_ROLE_OBJECT_PERMISSION> parampermission)
        {
            try
            {
                List <SEC_ROLE_OBJECT_PERMISSION> lstpermission = new List <SEC_ROLE_OBJECT_PERMISSION>();

                SEC_ROLE_OBJECT_PERMISSION permission;


                //bool submit = false;

                /*
                 * The below commented line not working due to
                 * explicit-construction-of-entity-type-in-query-is-not-allowed
                 * IEnumerable<SEC_ROLE_OBJECT_PERMISSION> lstpermission = from row in DB.SEC_OBJECTS_MASTER
                 *                                                      select new SEC_ROLE_OBJECT_PERMISSION
                 *                                                      {
                 *                                                          OBJECT_NAME = row.OBJECT_NAME,
                 *                                                          ROLE_NAME=rolename.ToUpper(),
                 *                                                          PERM_ADD=false,
                 *                                                          PERM_EDIT=false,
                 *                                                          PERM_VIEW=false,
                 *                                                          PERM_PRINT=false,
                 *                                                          DELETE_FLAG=false,
                 *                                                          ENTERED_DATE=DateTime.Now,
                 *                                                          ENTERED_BY=userInformation.UserName
                 *                                                      };
                 * DB.SEC_ROLE_OBJECT_PERMISSION.InsertAllOnSubmit(lstpermission.ToList());
                 * DB.SubmitChanges();
                 */

                IEnumerable <SEC_OBJECTS_MASTER> lstobjmaster = (from row in DB.SEC_OBJECTS_MASTER
                                                                 select row);

                foreach (SEC_OBJECTS_MASTER objmaster in lstobjmaster)
                {
                    permission              = new SEC_ROLE_OBJECT_PERMISSION();
                    permission.ROWID        = Guid.NewGuid();
                    permission.ROLE_NAME    = rolename;
                    permission.DELETE_FLAG  = false;
                    permission.ENTERED_DATE = DateTime.Now;
                    permission.ENTERED_BY   = userInformation.UserName;
                    permission.OBJECT_NAME  = objmaster.OBJECT_NAME;
                    permission.PERM_ADD     = false;
                    permission.PERM_DELETE  = false;
                    permission.PERM_EDIT    = false;
                    permission.PERM_PRINT   = false;
                    permission.PERM_VIEW    = false;
                    permission.PERM_SHOW    = false;
                    lstpermission.Add(permission);
                    ///DB.SEC_ROLE_OBJECT_PERMISSION.InsertOnSubmit(permission);
                }
                parampermission = lstpermission;
                return(true);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
Exemplo n.º 3
0
 public PermissionViewModel(UserInformation userInformation, string roleName)
 {
     _secRoleObjectPermission = new SEC_ROLE_OBJECT_PERMISSION();
     _permissionDet           = new PermissionDet(userInformation);
     Permission = _permissionDet.GetRolePermissionList(roleName);
     _roleName  = roleName;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Used to set rights of the Action Buttones
        /// </summary>
        /// <param name="SourceName">Name of Form</param>
        /// <param name="addButton">AddButton Object</param>
        /// <param name="editButton">EditButton Object</param>
        /// <param name="deleteButton">DeleteButton Object</param>
        /// <param name="printButton">PrintButton Object</param>
        /// <param name="viewButton">ViewButton Object</param>
        public void SetUserRights(string SourceName, Button addButton, Button editButton, Button deleteButton, Button printButton, Button viewButton = null)
        {
            SEC_ROLE_OBJECT_PERMISSION rolePermission = null;

            try
            {
                if (SourceName.IsNotNullOrEmpty())
                {
                    rolePermission = (from row in DB.SEC_ROLE_OBJECT_PERMISSION
                                      where Convert.ToBoolean(row.DELETE_FLAG) == false &&
                                      row.OBJECT_NAME.ToUpper() == SourceName.ToUpper() &&
                                      row.ROLE_NAME.ToUpper() == userRole.ToUpper()
                                      select row).SingleOrDefault();

                    if (!rolePermission.IsNotNullOrEmpty())
                    {
                        rolePermission             = new SEC_ROLE_OBJECT_PERMISSION();
                        rolePermission.PERM_ADD    = true;
                        rolePermission.PERM_EDIT   = true;
                        rolePermission.PERM_VIEW   = true;
                        rolePermission.PERM_DELETE = true;
                        rolePermission.PERM_PRINT  = true;
                    }

                    if (addButton.IsNotNullOrEmpty())
                    {
                        addButton.IsEnabled = rolePermission.PERM_ADD.ToBooleanAsString();
                    }
                    if (editButton.IsNotNullOrEmpty())
                    {
                        editButton.IsEnabled = rolePermission.PERM_EDIT.ToBooleanAsString();
                    }
                    if (deleteButton.IsNotNullOrEmpty())
                    {
                        deleteButton.IsEnabled = rolePermission.PERM_VIEW.ToBooleanAsString();
                    }
                    if (printButton.IsNotNullOrEmpty())
                    {
                        printButton.IsEnabled = rolePermission.PERM_DELETE.ToBooleanAsString();
                    }
                    if (viewButton.IsNotNullOrEmpty())
                    {
                        viewButton.IsEnabled = rolePermission.PERM_PRINT.ToBooleanAsString();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                rolePermission = null;
            }
        }
Exemplo n.º 5
0
        public bool SavePermission(DataTable permission, string rolename)
        {
            try
            {
                SEC_ROLE_OBJECT_PERMISSION sc = new SEC_ROLE_OBJECT_PERMISSION();

                EnumerableRowCollection <SEC_ROLE_OBJECT_PERMISSION> sec_role_object_permission_arr = from row in permission.AsEnumerable()
                                                                                                      select new SEC_ROLE_OBJECT_PERMISSION
                {
                    ROLE_NAME    = row["ROLE_NAME"].ToValueAsString(),
                    OBJECT_NAME  = row["opn_code"].ToValueAsString(),
                    PERM_ADD     = row["PERM_ADD"].ToBooleanAsString(),
                    PERM_DELETE  = row["PERM_DELETE"].ToBooleanAsString(),
                    PERM_EDIT    = row["PERM_EDIT"].ToBooleanAsString(),
                    PERM_PRINT   = row["PERM_PRINT"].ToBooleanAsString(),
                    DELETE_FLAG  = false,
                    ENTERED_BY   = row["ENTERED_BY"].ToValueAsString(),
                    ENTERED_DATE = Convert.ToDateTime(row["ENTERED_DATE"]),
                    UPDATED_DATE = System.DateTime.Now,
                    UPDATED_BY   = userInformation.UserName
                };



                foreach (SEC_ROLE_OBJECT_PERMISSION sec_role_object_permission in sec_role_object_permission_arr)
                {
                    //DB.SEC_ROLE_OBJECT_PERMISSION.Attach(sec_role_object_permission);
                }
                DB.SubmitChanges();
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);

                return(false);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
Exemplo n.º 6
0
        public PermissionViewModel(UserInformation userInformation, string roleName)
        {
            _secRoleObjectPermission = new SEC_ROLE_OBJECT_PERMISSION();
            _permissionDet           = new PermissionDet(userInformation);
            Permission = _permissionDet.GetRolePermissionList(roleName);
            _roleName  = roleName;

            foreach (SEC_ROLE_OBJECT_PERMISSION perm in Permission)
            {
                if (!_permissionDet.IsPrintDisable(perm.OBJECT_NAME))
                {
                    perm.PERM_PRINT = false;
                    perm.PERM_VIEW  = false;
                }
            }

            //var checkedcnt = Permission.Where(perm => perm.PERM_PRINT == true);
            //var cnt = Permission.Where(perm => _permissionDet.IsPrintDisable(perm.OBJECT_NAME));
            //chkSelectAllPrint.IsChecked = (checkedcnt.Count() == cnt.Count() ? true : false);
        }