Exemple #1
0
        /// <summary>
        /// assign default roles administrator for the new user
        /// </summary>
        /// <param name="username"></param>
        private bool AssignRolesForUser(string username)
        {
            SEC_USER_ROLES sec_user_roles = null;

            try
            {
                sec_user_roles              = new SEC_USER_ROLES();
                sec_user_roles.USER_NAME    = username;
                sec_user_roles.ROLE_NAME    = "Administrator";
                sec_user_roles.ROWID        = Guid.NewGuid();
                sec_user_roles.DELETE_FLAG  = false;
                sec_user_roles.ENTERED_DATE = serverDateTime;
                sec_user_roles.ENTERED_BY   = userInformation.UserName;
                DB.SEC_USER_ROLES.InsertOnSubmit(sec_user_roles);
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);

                return(false);
            }
            catch (Exception ex)
            {
                ex.LogException();
                DB.SEC_USER_ROLES.DeleteOnSubmit(sec_user_roles);
            }
            return(false);
        }
Exemple #2
0
        public string GetUserRole(string userName)
        {
            string returnValue = "";

            try
            {
                if (DB.IsNotNullOrEmpty())
                {
                    SEC_USER_ROLES userRoles = (from row in DB.SEC_USER_ROLES
                                                where
                                                row.USER_NAME == userName
                                                orderby row.ROLE_NAME
                                                select row).FirstOrDefault();
                    if (userRoles.IsNotNullOrEmpty())
                    {
                        returnValue = userRoles.ROLE_NAME;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
            return(returnValue);
        }
        /// <summary>
        /// Add the selected roles
        /// </summary>
        private void AddSelectedRoles()
        {
            SEC_USER_ROLES secuserroles;

            try
            {
                if (_selectedItemsRoleMaster != null)
                {
                    while (_selectedItemsRoleMaster.Count > 0)
                    {
                        SEC_ROLES_MASTER srm = (SEC_ROLES_MASTER)_selectedItemsRoleMaster[0];
                        secuserroles           = new SEC_USER_ROLES();
                        secuserroles.ROLE_NAME = srm.ROLE_NAME;
                        secuserroles.USER_NAME = _userName;
                        Sec_Roles_Master_List.Remove(srm);
                        Sec_User_Roles_List.Add(secuserroles);
                    }
                    NotifyPropertyChanged("Sec_User_Roles_List");
                    NotifyPropertyChanged("Sec_Roles_Master_List");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Process Designer");
            }
        }
        /// <summary>
        /// Remove the selected roles
        /// </summary>
        private void RemoveSelectedRoles()
        {
            SEC_ROLES_MASTER secrolesmaster;

            try
            {
                if (_selectedItemsUserRole != null)
                {
                    while (_selectedItemsUserRole.Count > 0)
                    {
                        SEC_USER_ROLES srm = (SEC_USER_ROLES)_selectedItemsUserRole[0];
                        secrolesmaster           = new SEC_ROLES_MASTER();
                        secrolesmaster.ROLE_NAME = srm.ROLE_NAME;
                        Sec_Roles_Master_List.Add(secrolesmaster);
                        Sec_User_Roles_List.Remove(srm);
                    }
                    NotifyPropertyChanged("Sec_User_Roles_List");
                    NotifyPropertyChanged("Sec_Roles_Master_List");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Process Designer");
            }
        }
        /// <summary>
        /// Remove the selected roles
        /// </summary>
        private void RemoveSelectedRoles()
        {
            SEC_ROLES_MASTER secrolesmaster;

            try
            {
                if (_selectedItemsUserRole != null)
                {
                    while (_selectedItemsUserRole.Count > 0)
                    {
                        SEC_USER_ROLES srm = (SEC_USER_ROLES)_selectedItemsUserRole[0];
                        secrolesmaster           = new SEC_ROLES_MASTER();
                        secrolesmaster.ROLE_NAME = srm.ROLE_NAME;
                        Sec_Roles_Master_List.Add(secrolesmaster);
                        Sec_User_Roles_List.Remove(srm);
                    }
                    NotifyPropertyChanged("Sec_User_Roles_List");
                    NotifyPropertyChanged("Sec_Roles_Master_List");
                }
                SelectListItem();
                EnableOrDisableSelect();
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
        /// <summary>
        /// Save the roles for the selected user
        /// </summary>
        /// <param name="lstrole"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool SaveRolesForTheUser(ObservableCollection <SEC_USER_ROLES> lstrole, string username)
        {
            bool submit = false;
            bool insert = false;
            List <SEC_USER_ROLES> lstsecuserroles;
            SEC_USER_ROLES        newsecuser = new SEC_USER_ROLES();

            try
            {
                lstsecuserroles = (from role in DB.SEC_USER_ROLES
                                   where
                                   role.USER_NAME.ToUpper().Trim() == username.ToUpper().Trim()
                                   select role).ToList <SEC_USER_ROLES>();
                DB.SEC_USER_ROLES.DeleteAllOnSubmit(lstsecuserroles);
                DB.SubmitChanges();



                foreach (SEC_USER_ROLES secuserroles in lstrole)
                {
                    newsecuser              = new SEC_USER_ROLES();
                    newsecuser.DELETE_FLAG  = false;
                    newsecuser.ENTERED_BY   = username;
                    newsecuser.ENTERED_DATE = serverDateTime;
                    newsecuser.IDPK         = 0;
                    newsecuser.ROLE_NAME    = secuserroles.ROLE_NAME;
                    newsecuser.ROWID        = Guid.NewGuid();
                    newsecuser.USER_NAME    = username;
                    insert = true;
                    DB.SEC_USER_ROLES.InsertOnSubmit(newsecuser);
                    submit = true;
                    DB.SubmitChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (submit == true)
                {
                    if (insert == true)
                    {
                        DB.SEC_USER_ROLES.DeleteOnSubmit(newsecuser);
                        DB.SubmitChanges();
                    }
                }
                throw ex.LogException();
            }
        }
        /// <summary>
        /// Add all the roles
        /// </summary>
        private void AddAllRoles()
        {
            SEC_USER_ROLES secuserroles;

            try
            {
                foreach (SEC_ROLES_MASTER srm in Sec_Roles_Master_List)
                {
                    secuserroles           = new SEC_USER_ROLES();
                    secuserroles.ROLE_NAME = srm.ROLE_NAME;
                    secuserroles.USER_NAME = _userName;
                    Sec_User_Roles_List.Add(secuserroles);
                }
                Sec_Roles_Master_List.Clear();
                NotifyPropertyChanged("Sec_User_Roles_List");
                NotifyPropertyChanged("Sec_Roles_Master_List");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Process Designer");
            }
        }