Esempio n. 1
0
        /// <summary>
        /// To delete the permission details by id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public string DeletePermission(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 PermissionRepository(session.DatabaseId()))
                    {
                        var permission = repository.GetPermissionIDDetails(id);
                        if (permission != null)
                        {
                            int assignPrmsnCount = repository.AssignPermissionCount(id);
                            if (assignPrmsnCount == 0)
                            {
                                repository.DeletePermission(permission);
                                msg = "Permission has been deleted successfully.";
                            }
                            else
                            {
                                msg = "This Permission 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);
        }