Esempio n. 1
0
        /// <summary>
        /// To delete the role details.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public string DeleteRole(int id, string accessToken)
        {
            string msg = string.Empty;

            try
            {
                dynamic session = null;
                if (!string.IsNullOrEmpty(accessToken))
                {
                    session = _sessionManager.GetSessionValues(accessToken);
                }
                if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
                {
                    using (var repository = new RoleRepository(session.DatabaseId()))
                    {
                        var role = repository.GetRoleIDDetails(id);
                        if (role != null)
                        {
                            int assignPrmsnCount = repository.AssignRoleCount(id);
                            if (assignPrmsnCount == 0)
                            {
                                repository.DeleteRole(role);
                                msg = "Role has been deleted successfully.";
                            }
                            else
                            {
                                msg = "This Role is already assigned canot be deleted.";
                            }
                        }
                        else
                        {
                            throw new Exception("Content not found by Id =" + id);
                        }
                    }
                }
                else
                {
                    throw new Exception("Unable to get database connection.");
                }
            }
            catch
            {
                throw;
            }
            return(msg);
        }